Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Getting and saving IPMI Infos

by theroninwins (Friar)
on Mar 22, 2006 at 09:00 UTC ( #538446=perlquestion: print w/replies, xml ) Need Help??

theroninwins has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

here is a little problem: I am using the ipmitool to get some infos of a hardware device.
The printout is like:
CPU 1 |3000 RPM |ok
Power Supply |unspecified |cr

and so on
I need it to be
CPU1=3000RPM=ok
Power Supply=unspecified=cr

foreach $line(@saved) { $tmp=s/\|/\=/,$line; @sort=$tmp; } open OUTPUT, ">>ipmiinfo.txt"; print OUTPUT @sort, "\n"; close OUTPUT;
I read the lines into @saved (that works) but the rest doesn't and it overwrites the lines aas well.

Does anyone have an idea how to sort this one out?

Replies are listed 'Best First'.
Re: Getting and saving IPMI Infos
by Melly (Hermit) on Mar 22, 2006 at 09:20 UTC

    You have three problems in your script

    1. "$tmp=s/\|/\=/,$line;" I've no idea what $tmp and $line will do in this context, but you are neither checking $line nor assigning to $tmp - use =~ if you are not running a regex against $_ - and $tmp is superfluous
    2. You will need to use the 'g' (global) modifier, otherwise you will only change the first occurence of '|'
    3. If you want to get rid of spaces (as you seem to imply), then you will need to include this in your regex
    $saved[0] = 'CPU 1 |3000 RPM |ok'; $saved[1] = 'Power Supply |unspecified |cr'; open OUTPUT, ">>ipmiinfo.txt"; foreach $line(@saved){ $line =~ s/\s*\|\s*/\=/g; print OUTPUT "$line\n"; } close OUTPUT;
    Tom Melly, tom@tomandlu.co.uk
      Thanks for the help. Indeed I want to get rid of the spaces.
Re: Getting and saving IPMI Infos
by timos (Beadle) on Mar 22, 2006 at 09:12 UTC
    What's wrong with
    foreach (@saved) { s/|/=/; push @sort, $_; } ...

      Or...

      @sort = map { s/ |/=/ } @saved;


      --chargrill
      $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://538446]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2022-05-19 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?