in reply to telling script to read from next line
That code will loop through your data file, line by line. By the time it's finished executing, it will print the url from each line of your data file.# You are using strict, right??? :-) use strict; my $adfile = 'banners.dat'; open(FILE, $adfile) || die "Can't open $adfile"; # Loops through the data file, 1 line at a time while(<FILE>) { # Split apart the line of data, put it in an array my @part = split(/\|/, $_); # Print's the url from the data line print "$part[0]\n"; } # Close up the file close(FILE);
As a final note, I noticed that you were accessing elements in the @part array by using syntax like @array[0]. Actually, the correct syntax to access a single element in an array is $array[0] and $array[1]. It's using the $, instead of the @. The @ is for referring to an entire array or array slice. The $ is used to refer to one, scalar value, such as a single element in an array.srand; # This chooses a random line, and puts that line into # the var $line. rand($.) < 1 && ($line = $_) while <FILE>; # Now you can split it my @part = split(/\|/,$line); # And then do whatever else with it... print "$part[0] $part[1] $part[2] ... ";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: telling script to read from next line
by ginocapelli (Acolyte) on Jul 08, 2001 at 16:55 UTC | |
|
Re: Re: telling script to read from next line
by Anonymous Monk on Jul 08, 2001 at 16:52 UTC |