in reply to Spliting a delimited string into variables
You print $line->[0] which is quite different from $line[0]. How this prints "371225..." is beyond me.
You also do lots of strange things to my eye, but that is to be expected ;-). For example to copy @arr into @line (for which you used a loop) "@arr= @line;" would have been enough. The same goes for "my @lines= ($line[0]..."
Also using lots of variables called $line, $lines, @line, @lines makes any program into an entry into the obfuscation contest. Differentiate your variables better
What you have been looking for might be this:
# starting with @arr having all the lines my @ticker; my @names=('ticket','dateadded','stime','etime','pri','SiteName','comm +ents'); my $i=0; foreach my $line (@arr) { my @items= split(/\|/, $line; print "ETime is $items[3]\n"; $ticker[$i]{$names{$_}}= $items[$_] for scalar @names; $i++; } # now $ticker[3]{SiteName} is SiteName of the fourth line
Note @ticker and $i are only neccessary if you want to operate on the data after the loop. If you just want to print or store the stuff, do that in the foreach loop above. You can also just use the split line you have in your script to fill the variables with the data inside the loop instead of using @items if it suits you better
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Spliting a delimited string into variables
by pissflaps (Initiate) on Apr 07, 2011 at 19:32 UTC | |
by jethro (Monsignor) on Apr 08, 2011 at 10:47 UTC | |
by pissflaps (Initiate) on Apr 08, 2011 at 21:23 UTC | |
by jethro (Monsignor) on Apr 11, 2011 at 08:55 UTC | |
|
Re^2: Spliting a delimited string into variables
by Anonymous Monk on Nov 28, 2013 at 14:49 UTC |