Kevin Pfeiffer wrote:
> In article <[EMAIL PROTECTED]>, John W. Krahn wrote:
>
> > "R. Joseph Newton" wrote:
> >>
> >> Kevin Pfeiffer wrote:
> >>
> >> > I'm looking at HTML::TokeParser. It expects a scalar with a filename or
> >> > a reference to a scalar containing the data to parse.
> >> >
> >> > This works fine:
> >> >
> >> > my $html;
> >> > if (@ARGV) { # get filename for TokeParser
> >> > $html = shift;
> >> > } else {
> >> > my @html = <>;
> >>
> >> Where is the diamond operator here supposed to be filled from?
> >
> > <> treats the elements of @ARGV as file names and opens them in order
> > and returns their contents but if @ARGV is empty it returns the contents
> > of STDIN.
>
> This is what I'm stuck on - is there a way to determine if STDIN is
> getting/is going to get/has gotten any contents?
>
> I thought I would just check with "unless @html...", but the script never
> gets that far, it's waiting for <STDIN> which never arrives.
>
> $ ./myscript
>
> I just thought that if @ARGV is empty and nothing is being piped to the
> script that I should be able to print a usage message.
Not the provlem at all, Kevin. The problem is those damned extra operators, in
this case the reference-to operator '\' preceding your join statement. Itr
should be one or the other, either join or take a reference. Doing both just
toasts the code:
Greetings! E:\d_drive\perlStuff>perl -w
my $html;
if (@ARGV) { # get filename for TokeParser
$html = shift;
} else {
my @html = <>;
$html = \(join '', @html); # pass scalar ref to module
}
open IN, $html;
print "$_" while (<IN>);
^Z
FileTest.html
^Z
readline() on closed filehandle IN at - line 9.
Greetings! E:\d_drive\perlStuff>perl -w
my $html;
if (@ARGV) { # get filename for TokeParser
$html = shift;
} else {
my @html = <>;
$html = \(join '', @html); # pass scalar ref to module
}
chomp $html;
open IN, $html;
print "$_" while (<IN>);
^Z
FileTest.html
^Z
readline() on closed filehandle IN at - line 10.
[snip--about five minor adjustments]
Greetings! E:\d_drive\perlStuff>perl -w
my $html;
if (@ARGV) { # get filename for TokeParser
$html = shift;
} else {
my @html = <>;
print "$_\n" for (@html);
$html = (join '', @html); # pass [either] scalar [or] ref [to
array] to module
print "$html\n";
}
chomp $html;
print "$html\n";
open IN, $html;
print "$_" while (<IN>);
^Z
FileTest.html
^Z
FileTest.html
FileTest.html
FileTest.html
<html>
<head>
<title> File Test </title>
</head>
<body>
<form method="POST" action="FileTest.cgi" enctype="multipart/form-data">
<input name="up_file" type="file" value="my_test.txt">
<input type="submit">
</form>
</html>
Greetings! E:\d_drive\perlStuff>
Joseph
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]