Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Need help with a simple perl script

by uday_sagar (Scribe)
on May 23, 2012 at 10:04 UTC ( [id://971999]=note: print w/replies, xml ) Need Help??


in reply to Need help with a simple perl script

Getting the same output that you wanted!

And i think the code you have given needs slight modification:

1. for loop to be included in while

2. $_="|" for $"="|"

(I know you knew these :-))

Here I have modified.

my %c; while( <> ){ chomp; my($c2,$c4,$c12)=(split/\|/)[1,3,11]; $c{"$c2|$c4"}||=[$_,0]; ++$c{"$c2|$c4"}[1] if $c12=~/\S/; $_="|"; for( sort keys %c ){ print "@{$c{$_}}\n"; } }

Replies are listed 'Best First'.
Re^2: Need help with a simple perl script
by choroba (Cardinal) on May 23, 2012 at 12:07 UTC
    Actually, no. Why should anyone set $_ to anything just to overwrite the value in a for loop? The code works - why does it need any modification? See perlvar for the special variable $".

      Okay, I agree with $". Thanks

      For the while loop, as "print" is not contained in while, it ll take the inputs all the time without printing anything.

        For the while loop, as "print" is not contained in while, it ll take the inputs all the time without printing anything.
        Not really. "print" is in a for loop, and it prints the output as desired, because the for loop uses the implicit variable $_.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found