Perl question
dsr at tao.merseine.nu
dsr at tao.merseine.nu
Wed May 21 17:23:20 EDT 2003
On Wed, May 21, 2003 at 04:52:40PM -0400, Eric Schwartz wrote:
> I have a perl programing question, any help you guys could offer would be
> greatly appreciated.
> I am trying to search an HTML page for specific data. I have bolded the
> text that I want to separate. The problem is that the next piece of HTML
> after this is for Cyan cartridge. And I want to save BLACK CARTRIDGE:
> Estimated pages Remaining: 6798, then after that do the Cyan and so
> forth. I don't know how to modify the code you wrote for me, to save Black
> Cartridge, then save estimated pages remaining and the number after it,
> without confusing it for the "cyan" estimated pages remaining. I hope this
> question is not too confusing, as I am new to programing, I appreciate all
> your help. Thanks again
So this is code that you didn't write yourself, that you are trying to
modify?
OK. I strongly recommend you start by buying a copy of "Learning Perl"
from O'Reilly, and after that a copy of "Programming Perl".
Next, always "use strict;".
Next, always enable warnings by invoking the perl interpreter with -w.
> Here is a piece of the perl that I am using, and does not seem to be
> working. Remember I need to pull all of the bolded stuff in order.
>
> $buffer = get('http://ipaddress);
This won't work. There are unbalanced quotes. And do you define &get
somewhere?
> print "\nHP 4600 PRINTER STATUS\n\n";
This will print a string.
> ($etapagerem) = $buffer
1. There's no semicolon at the end of this statement.
2. You are assigning a scalar to a list containing exactly one scalar,
which won't work because a scalar is not a list.
> =~ /BLACK CARTRIDGE\s*(?:<.*?>\s*)/s;
Assuming you are continuing from the last line, you appear to be
confused as to what constitutes a regexp. "man perlre" will explain them
to you, if you read it carefully.
> print "Estimated Pages Remaining: $etapagerem\n";
This prints a string with an interpolated scalar.; I have no idea what
the contents of that var will be.
May I suggest that what you really want is something along the lines of
this pseudoperlcode:
----
@httppage = `wget http://ipaddress`;
foreach my $line in @httppage {
if ($line =~ /a good regex/) {$black = $1};
if ($line =~ /another regex/) {$green = $1};
if ($line =~ /yetanother regex/) {$red = $1};
if ($line =~ /someother regex/) {$blue = $1};
if ($line =~ /some regex/) {$pagecount = $1};
};
print "Black percentage: $black \n";
print "Red percentage: $red \n";
print "Blue percentage: $blue \n";
print "Green percentage: $green \n\n";
print "Estimated pages left: $pagecount \n";
----
-dsr-
--
Network engineer / pre-sales engineer available in the Boston area.
http://tao.merseine.nu/~dsr
More information about the Discuss
mailing list