On Friday 15 June 2001 18:23, steve wrote:
> hi,
>
> im trying to write a program that takes the daily topten from
> showbizdata.com and formats it in an email. i have everything working great
> except the format part. i tried the format function but it doesnt seem to
> want to work in arrays and i am really bad at grabbing the stuff in scalar
> (as a matter of fact, out of 20 tries, i have grabbed the topten or even
> anything at all in scalar context for a total of 0 times =( ). so what i
> am trying to do is this:
>
> for (my $f=0; $f <= $#topten; $f++)
> {
> $rank[$f] = substr($topten[$f], 2, 3);
> $title[$f] = substr($topten[$f], 7, 30);
> $gross[$f] = substr($topten[$f], 50, 4);
> $grosstodate[$f] = substr($topten[$f], 60, 8);
> }
>
> # *************************************************
> for (my $g = 0; $g <= $#topten; $g++)
> {
> $topten[$g] = ("$rank[$g]", "\t", "$title[$g]", "\t", "$gross[$g]",
> "\t", "$grosstodate[$g]", "\n");
> }
> # ***************************************************
> print"@topten\n";
>
>
> the substr grabs all work pretty much ok, but when i try to put them back
> in topten (the lines between the comment lines) i get useless use of a
> string in void context...i tried grouping the elements with only
> double-quotes around the tab but it didnt work. any suggestions would be
> appreciated. thanks
> steve
>
> ---Steve
You probably want to put a string into $topten[$g]; to do this, create a
string with join() function:
$topten[$g] =
join("\t", $rank[$g], $title[$g], $gross[$g], $grosstodate[$g]) . "\n";
otherwise you are storing a list into scalar variable and that does not work
(you could also replace commas with dots, but join() is far cleaner).
Also, it's better to rewrite for() as
foreach my $g (0..$#topten)
((the same applies to previous for()).
Also, maybe it's a bit more flexible to store @topten lines without the
newline, and then print them out with
print map "$_\n", @topten;
--
Ondrej Par
Internet Securities
Software Engineer
e-mail: [EMAIL PROTECTED]
Phone: +420 2 222 543 45 ext. 112