Re: hash

[email protected] (Bobby)
Newsgroups perl.beginners
Message-ID <[email protected]>
Sorry Rodrick, i didn't gave enough info. This is part of a longer Perl script that I inherited from a former co-worker. The feed actually contains more info than that i gave. I just needed to add the logic described in my previous email to that existing script. 

Rodrick Brown <[email protected]> wrote: On Thu, May 22, 2008 at 12:39 PM, Bobby  wrote:
> Hi all,
>
> I have a flat file that contains a pid, us_size and euro_size. I want to create read in the file and create one hash for the us_size (%US) and the other for the euro_size (%EURO). Then i want to do a print statement if the pid value in the us_size hash is equal to pid value in the euro_size hash...maybe IF ($US{$pid} = $EURO{$pid}) {print statement...}.
>
> The part where i'm stuck on is how to assign the data into a hash and do the comparison, could one of you help me with the Perl's syntax or point in the right direction?
>
> Thanks much!
>
>
> pid|us_size|euro_size
> 1|10|34
> 2|11|35
> 3|12|37
> 4|13|
>
>
>

Why do you need a hash?

[svcprd@nycplx01a ~]$ cat /tmp/out
1|10|34
2|11|35
3|12|37
4|13|13

[svcprd@nycplx01a ~]$ perl -nle '($pid,$u,$e) = split/\|/,$_; print
"PID: $pid US: $u EU: $e" if ($u =~ m/$e/)'  /tmp/out
PID: 4 US: 13 EU: 13

--
[ Rodrick R. Brown ]

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.