[24266] in Perl-Users-Digest
Perl-Users Digest, Issue: 6457 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 24 06:05:44 2004
Date: Sat, 24 Apr 2004 03:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 24 Apr 2004 Volume: 10 Number: 6457
Today's topics:
Re: assigning variable to a pipe (mike)
Re: Ben and Tassilo: about calling subs with & <uri.guttman@fmr.com>
Re: does any other language even have this feature? <jwkenne@attglobal.net>
Re: free source guestbook (finished) <krahnj@acm.org>
Re: Insecure dependency in unlink while running with -T <krahnj@acm.org>
Re: RFC: Text similarity <xxala_qumsiehxx@xxyahooxx.com>
script too slow - sometimes hangs <King@ask.for.email.invalid>
Re: slurp not working? ideas please! <tassilo.parseval@rwth-aachen.de>
Re: slurp not working? ideas please! <tadmc@augustmail.com>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: slurp not working? ideas please! <Joe.Smith@inwap.com>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: Text-oriented network protocols <Joe.Smith@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Apr 2004 22:55:25 -0700
From: s99999999s2003@yahoo.com (mike)
Subject: Re: assigning variable to a pipe
Message-Id: <dfd17ef4.0404232155.1d0b20ba@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c6ajsd$gs2$1@mamenchi.zrz.TU-Berlin.DE>...
> mike <s99999999s2003@yahoo.com> wrote in comp.lang.perl.misc:
> > hi
> >
> > i have a piece of code like this
> >
> > open CMD ,"| wc -l " or die "blah blah: $!\n";
> > print CMD "ls -l" ;
> >
> > how can i assign a variable (or array ) to store the output of print
> > CMD "ls -l" statement??
>
> That's "assigning a variable to a pipe"?
>
> It looks like what you're trying to do would be easier accomplished with
> a shell script. With Perl, you want IPC::Open2 for that.
>
> Anno
hi,thanks for the advise
i went back to try this out :
use IPC::Open2;
$pid = open2(\*Reader, \*Writer, "sql -Uuser -Sserver -Ppassword" );
print Writer qq(select * from this_table\ngo);
$body .= $_ while (<Reader>);
print "$body\n";
But it doesn't work. Would appreciate if anyone can help
thanks
PS:
The original code was
open SQL, "| sql -Uuser -Sserver -Ppassword " or die "Failed to open pipe: $!" ;
print SQL "select \* from this_table";
and the intention was to assign the output to a variable
------------------------------
Date: 23 Apr 2004 15:47:59 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Ben and Tassilo: about calling subs with &
Message-Id: <sisck7061no0.fsf@tripoli.fmr.com>
>>>>> "CR" == Chris Richmond <crichmon@filc8604.fm.intel.com> writes:
CR> Please correct this summarization if needed:
CR> You shouldn't use '&' when calling new-style subroutines that
CR> have been declared with prototypes because it disables arg
CR> checking. Otherwise, its still optional when calling with
CR> parens, required without, unless the subroutine is predeclared.
you forgot the case where &foo without parens will pass the current @_
directly to the called sub. and the other point is that it is considered
poor style. learning perl is just that, learning. note that the book
said only until you know the names of perl functions so you won't use
those for sub names. that should take too long for most perl newbies.
any perl users beyond that stage shouldn't use & for sub calls. and i
would even just teach foo() to newbies and never mention & except for
getting a code ref with \&foo.
uri
------------------------------
Date: Sat, 24 Apr 2004 05:13:33 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: does any other language even have this feature?
Message-Id: <1Imic.120$t26.214630@news4.srv.hcvlny.cv.net>
Ala Qumsieh wrote:
> Sherm Pendley wrote:
>
>> valued customer wrote:
>>
>>
>>> Is there any other programming environment that has this
>>> feature? Can anyone name even one??
>>
>>
>>
>> Perl borrowed the "here document" idea from UNIX shells like Bash,
>> CSH, etc.
>> I think it would be a bit of a stretch to refer to that as a "programming
>> environment," though. ;-)
>
>
> I don't think the OP was talking about heredocs. He mentioned
> "quote-like operators" which, to me at least, refers to q// and qq//
> which are different from heredocs. His remark seems to refer to the fact
> that Perl gives you the option to use your favourite delimiter which is
> very useful. I don't know of any other languages that offers this.
Ruby has %q(abc) equal to 'abc' (and %q(a(b)c) equal to 'a(b)c'),
%Q(abc\n) equal to "abc\n" (and %Q(a(b)c\n) equal to "a(b)c\n"),
and %/abc\n/ equal to "abc\n".
--
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood.html
------------------------------
Date: Sat, 24 Apr 2004 02:38:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: free source guestbook (finished)
Message-Id: <4089D2F8.3F507DB8@acm.org>
Michele Dondi wrote:
>
> On Thu, 22 Apr 2004 11:33:23 -0700, "Robin" <robin @ infusedlight.net>
> wrote:
>
> >soon. This is great advice. BTW, the /g modifier means global replace.
>
> I have a *slight* (but mind you: only very slight!) feeling that
> Tassilo already knows what /g does mean, but that he was asking *why*
> you were doing a global replace!
Actually the OP wasn't doing a global replace. He was using /g on the
match operator in a boolean context which makes no sense at all. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 24 Apr 2004 01:52:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Insecure dependency in unlink while running with -T switch
Message-Id: <4089C832.34F7969D@acm.org>
Regent wrote:
>
> I must say I'm a newbie, writing a script that tries to unlink a
> particular file. Both the name of the file and that of the folder are
> variable scalar strings. Now that I habitually write with -T and
> strictures, I always get the error message "Insecure dependency in
> unlink while running with -T switch". The relevant block of code:
>
> if ("$root/$uploadDir/$origfn" ne "")
"$root/$uploadDir/$origfn" will NEVER be equal to "" because you have
two literal / characters in the string.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 24 Apr 2004 03:25:21 GMT
From: Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: RFC: Text similarity
Message-Id: <B6lic.421$zw7.279@newssvr27.news.prodigy.com>
Tore Aursand wrote:
> Any comments are appreciated! Thanks.
I would suggest taking your question to the perlai mailing list. I
recall a discussion about a similar problem a while ago.
--Ala
------------------------------
Date: Sat, 24 Apr 2004 08:12:16 GMT
From: The King of Pots and Pans <King@ask.for.email.invalid>
Subject: script too slow - sometimes hangs
Message-Id: <Ajpic.90718$U83.36176@fed1read03>
I wrote the following perl script to wander through my hard drive
(from current working directory) and tell me how many of which file
types I have. It works for small directory hierarchies. It seems to
freeze up on some arbitrary file when trundling through a large
directory hierarchy. Not sure why.
It uses the 'file' shell command, and is extremely slow! How could
this script accomplish the same goal faster?
Here is a sample of the output:
[steve@sol testcode]$ ./classify_files.pl
Classifying all files recursively...
Found 902 files.
436 - ASCII C program text
252 - C++ program text
85 - directory
38 - ASCII text
15 - ASCII C++ program text
14 - ASCII English text
13 - ASCII C program text, with CRLF line terminators
9 - a /usr/bin/perl -w script text executable
6 - ASCII text, with CRLF line terminators
4 - a /usr/bin/perl script text executable
4 - Bourne-Again shell script text executable
3 - ASCII make commands text
2 - ASCII C program text, with very long lines
2 - ISO-8859 C program text, with CRLF line terminators
2 - ASCII text, with very long lines, with CRLF line terminators
2 - ASCII C++ program text, with CRLF line terminators
2 - ASCII English text, with CRLF line terminators
2 - character Computer Graphics Metafile
2 - ASCII English text, with very long lines
1 - data
(etc ... the rest removed for brevity)
I am a neophyte perl person ... don't do much of it but would like to
get better. Certainly there are much much better ways to do this so
that is why I am asking. Thanks. Here's the perl script. How can it be
faster?
#!/usr/bin/perl -w
use strict;
use Cwd;
my %ftype;
my $total_files = 0;
sub classify_file
{
my $output = `file $_`;
# ignore these ones
if($output =~ /broken symbolic link/ or
$output =~ /symbolic link to/ or
$output =~ /can\'t stat/)
{
return;
}
# remove filename
$output =~ s/.+: //;
# increment value for this key
++$ftype{$output};
++$total_files;
}
sub recurse_dir
{
# only get cwd, faster that way
my $cwd = getcwd();
# read all files in current dir
foreach(<*>)
{
# recurse into directories
if(-d $_)
{
chdir("$cwd/$_");
recurse_dir($_);
chdir($cwd);
}
# perform the 'file' shell command
classify_file("$cwd/$_");
}
}
print "\nClassifying all files recursively...";
recurse_dir(getcwd());
print "\nFound $total_files files.";
print "\n";
# print in descending order by value
foreach my $key (sort { $ftype{$b} <=> $ftype{$a} } (keys %ftype))
{
print "$ftype{$key} - $key";
}
--
The King of Pots and Pans
------------------------------
Date: 24 Apr 2004 04:54:16 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: slurp not working? ideas please!
Message-Id: <c6crtn$acq87$1@ID-231055.news.uni-berlin.de>
Also sprach Geoff Cox:
> On 23 Apr 2004 21:21:42 GMT, "Tassilo v. Parseval"
><tassilo.parseval@rwth-aachen.de> wrote:
>
>>Hardly. Your script does not print anything option related. How should
>>it? Please show me the part of your code which is supposed to produce
>
> Tassilo,
>
> From the following, in sub start
>
> if ( $tagname eq 'option' ) {
>
> main::choice( $attr->{ value } );
>
> }
>
> the flow goes to say, the
>
> sub choice
>
> elsif ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
> intro($path);
> gcsestudentactivitiesfinance($path);
> }
>
> then to
>
> sub gcsestudentactivitiesfinance {
>
> my ($pattern) = @_;
>
> my $c = 0;
>
> open( INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php" );
>
> while (<INNN>) {
> last if /$pattern/;
> }
> my ( $curr, $next1, $next2, $next3 ) = <INNN>;
> close(INNN);
>
> if ( $next3 =~ /\$i\<(\d+);/ ) {
>
> my $nn = $1;
>
> print OUT ("<td valign='top'> \n");
> for ( $c = 1 ; $c < $nn ; $c++ ) {
> print OUT ( '<a href="' . $pattern
> . "/finance-doc"
> . $c . ".zip" . '">'
> . "Document$c"
> . "</a><br>"
> . "\n" );
> }
> print OUT ("</td></tr>\n");
> }
> }
>
> Which makes clear that I would have to let you have a sample part of
> yet another file, allphp2.php !!
Well, I did follow the control flow of your program up to this point.
But not even in intro() or gcsestudentactivitiesfinance() "<option..."
shows up.
I grepped your source code for 'option' and I got exactly one match,
which is in MyParser::start().
Thus, I simply cannot see how your program gives the output that you
described. <option ...> doesn't come out in the wrong order. It doesn't
come out at all. I don't think that the existance of allphp2.php would
change anything about that.
> Not sure how I could give you anything smaller than the total set of
> files in order to test for yourself .. ??
For one, it would help to remove the File::Find dependecy and post code
that only works on one input file. That way, someone could put the input
file and the two other files opened by your program into one directory.
The HTML input could even be appended to the program behind the
'__END__' marker so make it more self-contained. Your program could then
do a
$parser->parse_file(\*DATA);
Changing absolute paths to relative ones is also a good idea (in your
program and your accordingly in your data).
Furthermore, functions not called for the sample data should be thrown
out. Likewise branches in main::choice() that your program wont enter.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 24 Apr 2004 01:14:38 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: slurp not working? ideas please!
Message-Id: <slrnc8k1ee.6tj.tadmc@magna.augustmail.com>
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
> sub gcsestudentactivitiesfinance {
Quit joking around, the first of the month was a few weeks ago.
Thatisjusttoohardtoread.
(That_is_just_too_hard_to_read.)
Use the underscores Luke!
> open( INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php" );
<broken-record>
You should always, yes *always*, check the return value from open().
</broken-record>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 24 Apr 2004 06:42:04 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <tn2k80hfl0vr7k4jgmb3dltktrn9u2g386@4ax.com>
On 24 Apr 2004 04:54:16 GMT, "Tassilo v. Parseval"
<tassilo.parseval@rwth-aachen.de> wrote:
>I grepped your source code for 'option' and I got exactly one match,
>which is in MyParser::start().
>
>Thus, I simply cannot see how your program gives the output that you
>described. <option ...> doesn't come out in the wrong order. It doesn't
>come out at all. I don't think that the existance of allphp2.php would
>change anything about that.
Tassilo,
OK - my fault - I should have said that the output (using the value
for option from the allphp2.php file) would be, for example,
<a
href="docs/gcse/student-activities/business-location/location-doc1.zip">Document1</a><br>
but I was using the <option etc as shorthand to demonstrate that the
order of output is wrong ...
I will try to act on your other suggestions!
Cheers
Geoff
------------------------------
Date: Sat, 24 Apr 2004 07:19:50 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <0r4k80l7obdse8htkp0dbjlemqlj9833c7@4ax.com>
On 24 Apr 2004 04:54:16 GMT, "Tassilo v. Parseval"
<tassilo.parseval@rwth-aachen.de> wrote:
>For one, it would help to remove the File::Find dependecy and post code
>that only works on one input file. That way, someone could put the input
>file and the two other files opened by your program into one directory.
Tassilo,
OK - have tried to follow your suggestions in cutting down the code
etc.
The code and the 3 files test.htm, db.txt and allphp2.php can be in
the same folder. The results will appear in results.htm. Hope this can
allow you to see why the oder in results.htm is not the same as that
in test.htm ...
Cheers
Geoff
---------------tass2.pl ---------------------
package MyParser;
use base qw(HTML::Parser);
use strict;
use diagnostics;
my ($in_heading,$in_p, $fh);
sub register_fh {
$fh = $_[1];
}
sub reset { ($in_heading,$in_p)=(0,0)}
sub start {
my ( $self, $tagname, $attr, undef, $origtext ) = @_;
if ( $tagname eq 'h2' ) {
$in_heading = 1;
return;
}
if ( $tagname eq 'p' ) {
$in_p = 1;
return;
}
if ( $tagname eq 'option' ) {
main::choice( $attr->{ value } );
}
}
sub end {
my ( $self, $tagname, $origtext ) = @_;
if ( $tagname eq 'h2' ) {
$in_heading = 0;
return;
}
if ( $tagname eq 'p' ) {
$in_p = 0;
return;
}
}
sub text {
my ( $self, $origtext ) = @_;
print $fh "<h2>$origtext</h2> \n" if $in_heading;
print $fh "<p>$origtext</p> \n" if $in_p;
}
package main;
my $parser = MyParser->new;
my $name = "test.htm";
open( OUT, ">>results.htm" )
|| die "$name: $!";
print OUT ("<html><head><title>test</title>
</head><body> \n");
print OUT ("<table width='100%' border='1'> \n");
$parser->register_fh(\*OUT);
$parser->parse_file($name);
$parser->reset;
print OUT ("</body></html> \n");
sub choice {
my ($path) = @_;
if ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
intro($path);
gcsestudentactivitiesfinance($path);
} elsif ( $path =~ /docs\/gcse\/student-activities\/marketing/ ) {
intro($path);
gcsestudentactivitiesmarketing($path);
}
}
sub intro {
my ($pathhere) = @_;
open( INN, "db.txt" );
my $lineintro;
while ( defined( $lineintro = <INN> ) ) {
if ( $lineintro =~ /$pathhere','(.*?)'\)\;/ ) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}
sub gcsestudentactivitiesfinance {
my ($pattern) = @_;
my $c = 0;
open( INNN, "allphp2.php" )
|| die "can't open allphp2.php: $! \n";
while (<INNN>) {
last if /$pattern/;
}
my ( $curr, $next1, $next2, $next3 ) = <INNN>;
close(INNN);
if ( $next3 =~ /\$i\<(\d+);/ ) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ( $c = 1 ; $c < $nn ; $c++ ) {
print OUT ( '<a href="' . $pattern
. "/finance-doc"
. $c . ".zip" . '">'
. "Document$c"
. "</a><br>"
. "\n" );
}
print OUT ("</td></tr>\n");
}
}
sub gcsestudentactivitiesmarketing {
my ($pattern) = @_;
my $c = 0;
open( INNN, "allphp2.php" )
|| die "can't open allphp2.php: $! \n";
while (<INNN>) {
last if /$pattern/;
}
my ( $curr, $next1, $next2, $next3 ) = <INNN>;
close(INNN);
if ( $next3 =~ /\$i\<(\d+);/ ) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ( $c = 1 ; $c < $nn ; $c++ ) {
print OUT ( '<a href="' . $pattern
. "/marketing-doc"
. $c . ".zip" . '">'
. "Document$c"
. "</a><br>"
. "\n" );
}
print OUT ("</td></tr>\n");
}
}
-------------- test.htm ----------------------
<html>
<head><title>test</title>
</head>
<body>
<h2>Finance </h2>
<p> description re Finance document</p>
<option
value="docs/gcse/student-activities/finance">Marketing</option>
<h2>Marketing</h2>
<p> description re marketing document </p>
<option
value="docs/gcse/student-activities/marketing">Marketing</option>
</body>
</html>
-------------- db.txt -------------------------
INSERT INTO total VALUES
('docs/gcse/student-activities/finance','<h3>GCSE Student Activities -
Finance</h3>1. methods of raising finance<br>2. don\'t call them
money<br>3. coloured breakeven point<br>4. The mug activity<br>5.
Cashflow and inflow<br>6. external influences on breakeven<br>7.
balance sheet<br>8. which account will you get me from');
INSERT INTO total VALUES
('docs/gcse/student-activities/marketing','<h3>GCSE Student Activities
- Marketing</h3>1. adverts-activity<br>. demand-and-supply<br>3.
market-research<br>4. market-segments<br>5. product-life-cycle<br>6.
promotions-and-business-objectives<br>7. supply-and-demand-2<br>8.
the-marketing-mix-and-types-of-economy<br>9. the-marketing-mix<br>10.
types-of-market-and-demand-and-supply<br>11.
types-of-ownership-and-the-marketing-mix');
-------------- allphp2.pl --------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
@require(dirname(__FILE__) . '/../../../config_php/config.php');
if (@$_POST['submit'] == 1)
{
if ($_POST['term'] == "") {
echo "<font color=#000000>No document chosen please select one</a> <p>
\n";
//echo "<a href='avce-assignments.php'><font color=#000000>Search
again</font></a> \n";
} else {
$query = "select * from total where " . $_POST['searchfield'] . "=" .
"'". $_POST['term'] . "'";
/* connect to the server */
$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");
/* select database */
if (mysql_select_db($conf['sql']['db'],$link)) {
/* make query */
$result = mysql_query($query, $link);
if ($result) {
if (mysql_num_rows($result) == "0") {
echo "<font color=#000000>Not found - try again with a different
term</a> <p>\n";
// echo "<a href='assignments.htm'><font color=#000000>Search
again</font></a> \n";
} else {
// echo "<B>Your query found ".mysql_num_rows($result)." hit(s)</B>";
echo "<TABLE width='100%' BORDER='1' width='100%' cellpadding='10'
align='center'>\n";
while ($row[] = mysql_fetch_array($result)) {
printf("<td valign='top'>%s </td>",$row[0]["intro"]);
}
switch ($_POST['term']) {
case $_POST['term'] == "docs/gcse/student-activities/finance":
{
echo "<td valign='top' width='10%'>";
echo "<b>Select Document</b><br>";
for ($i=1;$i<9;$i++) {
echo "<a href='". $_POST['term'] . "/finance-doc" . $i .".zip" .
"'>$i</a>";
echo "<br>";
}
echo "</td></tr>";
echo "</TABLE>\n";
}
break;
case $_POST['term'] == "docs/gcse/student-activities/marketing":
{
echo "<td valign='top' width='10%'>";
echo "<b>Select Document</b><br>";
for ($i=1;$i<12;$i++) {
echo "<a href='". $_POST['term'] . "/marketing-doc" . $i .".zip" .
"'>$i</a>";
echo "<br>";
}
echo "</td></tr>";
echo "</TABLE>\n";
}
break;
}
}
}
}
}
}
?>
</body>
</html>
------------------------------
Date: Sat, 24 Apr 2004 07:50:02 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: slurp not working? ideas please!
Message-Id: <K_oic.15794$aQ6.1136492@attbi_s51>
Richard Morse wrote:
> find sub {
> return if -d (some_function_to_get_cwd() . $_);
> ...
> }
Unless you explictly invoke no_chdir=>1 in the options to find(),
the current working directory is the one that contains the file.
Therefore you can use simply
return if -d $_;
to check if "$File::Find::dir/$_" is a subdirectory.
------------------------------
Date: Sat, 24 Apr 2004 09:22:04 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <tbck805e5nr1udg2nqllgo5hqq2bgjc8hq@4ax.com>
On Sat, 24 Apr 2004 07:50:02 GMT, Joe Smith <Joe.Smith@inwap.com>
wrote:
>Richard Morse wrote:
>
>> find sub {
>> return if -d (some_function_to_get_cwd() . $_);
>> ...
>> }
Thanks for that Richard.
Cheers
Geoff
>Unless you explictly invoke no_chdir=>1 in the options to find(),
>the current working directory is the one that contains the file.
>Therefore you can use simply
> return if -d $_;
>to check if "$File::Find::dir/$_" is a subdirectory.
------------------------------
Date: Sat, 24 Apr 2004 09:24:11 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <8eck80tmec533lh06q1scup1palecjki21@4ax.com>
On Thu, 22 Apr 2004 15:27:41 -0400, Richard Morse
<remorse@partners.org> wrote:
>In article <96fa801ru1jr3at8f3bek7jj2j3bli0am6@4ax.com>,
> Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
>
>> Anno
>>
>> the code as of now follows - I am confused re how the OOP fits in with
>> the File::Find ... but as I am using html files in the 1 folder have
>> removed the File::Find part .. but still get the warning re
>> uninitialized value in pattern match for the
>>
>> if ($next3 =~ /\$i\<(\d+);/) {
>>
>> in sub classroomnotes
>>
>> any ideas why?
>>
>
>Try doing the following:
Ricky,
sorry I missed your post ... Tassilo has put me straight re the OOP
part (see his posts here).
Cheers
Geoff
>
>> package MyParser;
>> use base qw(HTML::Parser);
>>
>[snip]
>> sub classroomnotes {
>>
>> my ($pattern) = @_;
>>
>> # print ("\$pattern has value $pattern \n");
>>
>> open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
>> die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";
>>
>> my $line = <INNN>;
>
> # since I don't see a chomp/chop anywhere, I'm assuming
> # that each line has a newline at the end already.
> print "line: ", $line;
>
>>
>> while (<INNN>){
>> last if /$pattern/;
>> }
>> my ($curr, $next1, $next2, $next3) = <INNN>;
>
> print "curr: ", $curr;
> print "next1: ", $next1;
> print "next2: ", $next2;
> print "next3: ", $next3;
> print "\n";
>
>> close (INNN);
>>
>> if ($next3 =~ /\$i\<(\d+);/) {
>> my $nn = $1;
>> print OUT ("<td valign='top'> \n");
>> for ($c=1;$c<$nn;$c++) {
>> print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
>> "Document$c" . "</a><br>" . "\n");
>> }
>> print OUT ("</td></tr>\n");
>> }
>> }
>>
>
>What does this tell you?
>
>Ricky
------------------------------
Date: Sat, 24 Apr 2004 07:38:47 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Text-oriented network protocols
Message-Id: <bQoic.15869$_L6.1207843@attbi_s53>
Mike Mimic wrote:
> I have just read in Programming Perl that Network protocols
> should be text based (ASCII, UTF-8 ...). Why is this
> better than binary data? Would not binary data be more
> compact and so it would require less bandwith?
Consider the FTP protocol. Once logged in, a typical dialog looks like:
==> cd pub
<== 250 CWD command successful.
==> bin
<== 200 Type set to I (image).
==> get movie.mpg
<== 226 BINARY Transfer complete.
=== 600,000,000 bytes
Here, the commands and responses are in ASCII, the data is transfered
in binary. If you were to use a binary dialog (such as a single byte
command codes instead of "cd " and "get ", and single byte responses),
the total transfer would be 600,000,019 bytes instead of 600,000,117.
A savings of 0.0000163%, but making it very difficult to debug manually.
With commands and responses in ASCII, debugging can be done by using
TELNET to port 21 and parsing the results by eyeball.
Another problem with network protocols in binary has to with sending
multibyte integers. Should the number 258 be sent as 0x0102 (16-bit
big endian), 0x00000102 (32-bit big endian), 0x0201 (16-bit little
endian), 0x02010000 (32-bit little endian), or as "2"+"5"+"8"+CR+LF
(byte-order independent).
Summary: network protocols are more flexible and easier to debug when
the commands and responses are plain text, and only the payload (raw
data) is transfered as a binary stream of single bytes.
-Joe
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6457
***************************************