hash of ref to array of arrays, lost all but the last element in hash
Dear all, I would like to construct a hash, whose value holds a reference to an array of arrays, however all the keys in my hash have the exact same value, which turns out to be the value of the last element I put it!! I felt that something is wrong in the data structure, that I should not keep re-using @match or @splice, they get overwritten, so I only came with the last one. But I am not sure how to fix it, or is there a way? Any insight is much appreciated!!! -Jennifer #! /usr/bin/perl -w my %hash; my $MatchLine; my $SVLine; while (STDIN) { chomp $_; if (/^Query=(\w+)$/) { if ($key) { @match = split (' ', $MatchLine); @splice = split (' ', $SVLine); $ref = [\@match, \@splice]; $hash{$key}= $ref; $key = $1; } else { $key =$1 } } elsif (/^MA:(.+)$/) { $MatchLine = $1; } elsif (/^SV:(.+)$/) { $SVLine = $1; } else { } } foreach $key (keys %hash) { print $key\n; print $_ for (@$mref); print \n; print $_ for (@$svref); print \n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
FW: hash, key value
-Original Message- From: Jennifer Pan Sent: Tuesday, August 21, 2001 6:08 PM To: '[EMAIL PROTECTED]' Subject: hash, key value Dear all: I would like to construct a hash, the value of each key is a bunch of refs to lists $value1 -- @list1 $value2 -- @list2 %hash{key} = $value3 --@list3 $value4 -- @list4 $value5 -- @list5 since I generate the %hash recursively, my question is that can the $value1 to $value6 be the same ( same string) for differrent hash keys? this could be a really niave question, but I really am not sure about the answer thanks a lot -jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
two .pl use each other?
I have two perl programs x1.pl and x2.pl In x1.pl, I really want to call x2.pl as a function to finish the task, is there a way to pack them so they can use one another? thank you! -Jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
chomp list
I have a file : #myfile.txt a b c d a c s g g o y g _END_ I wrote a perl script to put each line into a list; #/usr/bin/perl -w open (FH, myfile.txt) ; while ($LINE = FH) { chomp $LINE; push @list, $LINE; } close FH; print $_ for (@list); _END_ I expect to get a b c da c s gg o y g instead I got a b c d a c s g g o y g why didn't chomp work??!! any insight is appreciated -Jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
print the array values in a hash
I have a hash and the 'value' associated with each key is an array of strings. (I do not care the strings are in order, so I suppose an embedded hash would do too); I want to print out the keys and each element of the array that associated with each key I did: foreach $key (keys %hash) { print $key\n; print $hash{$key}.\n; } however, it printed out the number of total elements in the array instead of each element. How can I print out the whole array associated with each key? thanks a lot -Jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: URL access
Apologize for the naivety, but there are so many modules related with LWP at cpan ( I searched for LWP), which one do I download? And how do I know if we already have LWP module at our local machine? thank you very much!! -Jennifer Pan -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 3:49 PM To: Tyler Cruickshank; [EMAIL PROTECTED] Subject: Re: URL access This is exactly what LWP is for... it comes standard with activestate's distro of perl (www.activestate.com) but not with *nix iirc. you can grab the module from cpan and just read up on the docs of LWP::Simple it does all you need =) hth Jos - Original Message - From: Tyler Cruickshank [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, August 15, 2001 9:44 PM Subject: URL access Hello. Im looking for a little direction: I want to write a very simple script that goes out to a particular set of web sites (weather maps) and prints/saves their contents. Ive been reading about sockets and networking but I havent been able to glean the information that I think I need. Does anyone have a hint? Im interested in doing this either from a UNIX box or NT. Thanks very much. -Tyler Cruickshank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
grep repetitive elements?
I have two list, @list1 and @list2, each element @list1 is unique (could be a hash I suppose) I want to find out all the elements @list2 that is an element in list1 and have appeared two or more times I want to use GREP but I don't know how to grep certain element only when it happens 2 times, or is it possible? foreach $L1 (@list1) { if ( grep /$L1/ @list2 more than twice?) { print $L1; } many thanks!! _jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep repetitive elements?
thanks all! This works, and I am reading Perl cookbook. -Original Message- From: Jeff 'japhy/Marillion' Pinyan [mailto:[EMAIL PROTECTED]] Sent: Friday, August 10, 2001 10:44 AM To: Jennifer Pan Cc: [EMAIL PROTECTED] Subject: Re: grep repetitive elements? On Aug 10, Jeff 'japhy/Marillion' Pinyan said: my %freq; $freq{$_}++ for @list2; # create a hash of key - frequency for (@list1) { print $freq{$_} if $freq{$_} 1; } Rather, print $_ if $freq{$_} 1; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
if in a list
I want to test if AF1 is in my list @mylist; I did: foreach $LIST (@mylist) { if ($LIST = AF1) $boolean = 1; else $boolean = 0; } is there a more elegant way to do it? many thanks jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: if in a list
many thanks, jos and maxim, your suggestions were very helpful. jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
matrix construction
I download the matrix module from CPAN , http://search.cpan.org/doc/ULPFR/Math-Matrix-0.3/README, $a = new Math::Matrix ([rand,rand,rand], [rand,rand,rand], [rand,rand,rand]); , but I am still at lost as to how to construct a matrix so if I want to construct 1, 2,3, 1, 1, 1, 2, 3, 4 can I say : $a = new Math::Matrix ([1, 2, 3], [1, 1, 1], [2, 3, 4]); thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
open FILE problem
Hello all, I came across this problem opening up files that are fed in from command line using ls. I do not know why this script did not work. Appreciated any input. #!/usr/local/bin/perl # I am trying to feed all the files in this directory to do text processing and save the processed txt into an #output called outout.txt while ($LINE = STDIN) { chomp $LINE; open (AFILE, $LINE) or die ( cannot open $LINE); open X, output.txt; while ($LINE1 = AFILE) { $LINE1 =~ s/^\s*//; print X $LINE1; } close X; close AFILE; } at prompt I typed ls *.txt | perl format.pl it never worked it always die cannot open $LINE. I don't understand why thanks -jen
concatenate $FILENAME and .yyy
Hello all, I stdin a file name: xxx.txt and I would like to have a output file name called x.txt.yyy This is how I do it $FILENAME = STDIN; $output = $FILENAME.y; print $output; And the result is only .yyy How do I concatenate $FILENAME and .yyy? Thank you