Perl newbie (don't follow <> notation ????)
Posted: Wed Aug 04, 2004 8:08 am
Hi,
I'm just starting out in Perl and I'm trying to loop over lines of text to do this task....
and it noted that <> means "loop over these lines of text"
So I tried putting some text inside the <> and all it did at the end was printed the whole string same as the input.
I am aware that the above which is my version is meaningless but I'm sure if somebody could word it nicely I'd understand how to use the real solution that was given 
Also where do I use ^D?
Thanks
I'm just starting out in Perl and I'm trying to loop over lines of text to do this task....
this was the given solution to the problem....Write a script which assembles separate lines in to longer lines. A new line in the output is one that starts with at least two digits. All the lines which follow it, until the next occurrence of two digits at the start of a line, are a continuation of the earlier line. Eg
21 this
is all part
of
the same line
223 but this is different
Code: Select all
$var = "";
while (<>) {
if (/^\d\d/) {
print "$var\n";
$var = ""
}
$var .= $_;
}
print "$var\n"; # any leftover?So I tried putting some text inside the <> and all it did at the end was printed the whole string same as the input.
Code: Select all
$var = "";
while (<123 a line of text \nthis line should be the same as the first \n145 but this one should be different>) {
if (/^\d\d/) {
print "$var\n";
$var = ""
}
$var .= $_;
}
print "$var\n"; # any leftover?Also where do I use ^D?
Thanks