> -----Original Message-----
> From: Larsen, Errin M HMMA/IT 
> Sent: Thursday, February 10, 2005 2:37 PM
> To: beginners@perl.org
> Subject: Loops & regexps
> 
> 
> Hi everyone,
> 
> I've got a command (if you're familiar with EMC and 
> PowerPath, you'll recognize the output) that outputs a long 
> list of information like this:
> 

  << example output snipped>>

> 
> That's the output from ONE device, there are sometimes hundreds of
> these.  What I'd like to do is transform this   into the following:
> 

  << desired output snipped>>

> 
> I wrote some code to attempt this, but I'm way off ... I know 
> there's a way to do this, it's just eluding me.  The code I 
> was trying out is below.  I wouldn't run it, it fails miserably:
> 

  << Horrible Code snipped>>

> Thanks ahead-of-time for any help!
> 
> --Errin
> 

Ok, I got it working.  This code only works if you assume a correct
order, but with the command I'm using that order does not change:

  #!/usr/bin/perl

  use warnings;
  use strict;

  my @powerout = `powermt display dev=all`;
  my $name;
  my @devices;

  foreach( @powerout ) {
    $name = $1 if( /Pseudo.+(emc.+)$/ );
    push @devices, "$name -> $1" if( /(c\dt.+)s\d/ ); 
  }

  print "$_\n" foreach @devices

It turns out it was lot simpler than I was thinking.

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to