[24198] in Perl-Users-Digest
Perl-Users Digest, Issue: 6390 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 12 18:05:45 2004
Date: Mon, 12 Apr 2004 15:05:09 -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 Mon, 12 Apr 2004 Volume: 10 Number: 6390
Today's topics:
Can you use the "fork" function in Windows? (nub5)
How can I follow links in my website <dannywork5@hotmail.com>
Re: How can I follow links in my website <ebohlman@earthlink.net>
Re: How can I follow links in my website <postmaster@castleamber.com>
Re: How can I follow links in my website <dannywork5@hotmail.com>
Re: How can this be done? <remorse@partners.org>
how to do a reverse ip lookup of a DNS server ? <gp@nospm.hr>
Re: I cann't scale gif with correctly with perlmagick. <remorse@partners.org>
Re: Interacting w/another App on Win32 (Anthony M. Saffer)
IPC, buffering, and Win32 <perlcdr@mail.rumania>
Many filename arguments: EOF in "while(@slurp=<>){..}"? <fma@doe.carleton.ca>
Re: Many filename arguments: EOF in "while(@slurp=<>){. <tadmc@augustmail.com>
Newbie Question... (EddieJ)
Re: Newbie Question... <ittyspam@yahoo.com>
Re: Newbie Question... <dwall@fastmail.fm>
Re: Newbie Question... <glex_nospam@qwest.invalid>
Re: Newbie Question... <xx087@freenet.carleton.ca>
Re: Newbie Question... <ittyspam@yahoo.com>
PERL web addressing <ssadale@nospam.yahoo.com>
Re: perldoc incompetence: perlre /s <postmaster@castleamber.com>
Re: perldoc incompetence: perlre /s <perl@my-header.org>
Re: perldoc incompetence: perlre /s <postmaster@castleamber.com>
Questions about the Class::Contract module <jtc@shell.dimensional.com>
running multiple versions of perl <here@there.com>
SOAP:Lite Client - server message passing (pj)
Re: some sed to perl action... <thens@NOSPAMti.com>
Re: some sed to perl action... <xx087@freenet.carleton.ca>
Re: striped name to variable (GreenLight)
Re: striped name to variable (Sam Holden)
Re: Tough (for me) regex case <rob_perkins@hotmail.com>
Re: Why are arrays and hashes this way? (Xavier Noria)
Re: Writing to STDIN (Hobbit HK)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Apr 2004 13:58:35 -0700
From: rmiller_nub@yahoo.com (nub5)
Subject: Can you use the "fork" function in Windows?
Message-Id: <23e193ca.0404121258.2a9393d5@posting.google.com>
Hello all I'm trying to use the fork function for Windows 2000 Prof,
Perl version 5.005_002. My intent is to run a program and then return
back to the perl script for data processing. The code I'm am tryng to
use is below. However the program keep telling me that it does not
recognize the fork function.
$return_value = fork;
if ($return_value == 0)
{
print "\n** Starting program on$new__file **\n";
$exec_cmd =join(" ","prog.exe",$new_file);
system("$exec_cmd");
}
elsif (defined $return_value)
{
print "** Waiting to finish **\n";
$pid = wait;
print "** finished ** \n";
}
else {die "Fork Error on running $! \n";}
------------------------------
Date: Mon, 12 Apr 2004 15:06:11 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: How can I follow links in my website
Message-Id: <Dfyec.6859$467.1770765@news4.srv.hcvlny.cv.net>
I would like to browse a page in one of my websites and get info to populate
a database. But each page will have a NEXT and PREVIOUS link that takes you
to another page.
I need something to look at one page and save it to a file on the HD, then
follow the NEXT link and go to the next page, and do the same thing, and so
on.
Can this be done?
------------------------------
Date: 12 Apr 2004 15:54:31 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: How can I follow links in my website
Message-Id: <Xns94C96F8801115ebohlmanomsdevcom@130.133.1.4>
"Danny" <dannywork5@hotmail.com> wrote in
news:Dfyec.6859$467.1770765@news4.srv.hcvlny.cv.net:
> I would like to browse a page in one of my websites and get info to
> populate a database. But each page will have a NEXT and PREVIOUS link
> that takes you to another page.
>
> I need something to look at one page and save it to a file on the HD,
> then follow the NEXT link and go to the next page, and do the same
> thing, and so on.
>
> Can this be done?
Yep: LWP::Simple and HTML::LinkExtor together ought to do the trick.
------------------------------
Date: Mon, 12 Apr 2004 10:59:37 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: How can I follow links in my website
Message-Id: <407abcfb$0$24349$58c7af7e@news.kabelfoon.nl>
Danny wrote:
> I would like to browse a page in one of my websites and get info to populate
> a database. But each page will have a NEXT and PREVIOUS link that takes you
> to another page.
>
> I need something to look at one page and save it to a file on the HD, then
> follow the NEXT link and go to the next page, and do the same thing, and so
> on.
>
> Can this be done?
Yes.
check the lwpcookbook, and HTML::Parser, for example. It's possible to
not use the parser, but just a regexp if you know what you are doing :-D.
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: Mon, 12 Apr 2004 16:37:20 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: Re: How can I follow links in my website
Message-Id: <4Bzec.7292$467.2008135@news4.srv.hcvlny.cv.net>
"John Bokma" <postmaster@castleamber.com> wrote in message
news:407abcfb$0$24349$58c7af7e@news.kabelfoon.nl...
> Danny wrote:
>
> > I would like to browse a page in one of my websites and get info to
populate
> > a database. But each page will have a NEXT and PREVIOUS link that takes
you
> > to another page.
> >
> > I need something to look at one page and save it to a file on the HD,
then
> > follow the NEXT link and go to the next page, and do the same thing, and
so
> > on.
> >
> > Can this be done?
>
> Yes.
>
> check the lwpcookbook, and HTML::Parser, for example. It's possible to
> not use the parser, but just a regexp if you know what you are doing :-D.
>
> --
> John personal page: http://johnbokma.com/
>
> Experienced Perl / Java developer available - http://castleamber.com/
Thanks for your responses.
I have a sample that works, in that it gets a webpage, prints the contents
of the website to a text file and then prints all the links in the website.
Now I just want to follow the links in that website that have "nextpage" in
the link and so on (this means it goes to the next category page). and I
want to save each page to a text file like page1.txt, page2.txt etc etc
this script works but I am not sure where to put loops. I am still
learning.
HOw can I do this?
I would appreciate your help.
Thanks again
Danny
-------
use CGI;
$co = new CGI;
use LWP::Simple;
use HTML::LinkExtor;
print $co->header;
$html = get("http://www.website.com");
$link_extor = HTML::LinkExtor->new(\&handle_links);
$link_extor->parse($html);
use LWP::UserAgent;
$user_agent = new LWP::UserAgent;
$request = new HTTP::Request('GET','http://www.website.com');
$response = $user_agent->request($request);
open FILEHANDLE, ">file.txt";
print FILEHANDLE $response->{_content};
close FILEHANDLE;
sub handle_links
{
($tag, %links) = @_;
if ($tag eq 'a') {
foreach $key (keys %links) {
if ($key eq 'href') {
# I assume I put a test here for the NEXT link and then this gets
loades as above in REQUEST statement?
print "This is a link: $links{$key}.\n";
}
}
}
}
------------------------------
Date: Mon, 12 Apr 2004 11:39:49 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: How can this be done?
Message-Id: <remorse-B32C7D.11394912042004@plato.harvard.edu>
In article <9MKdc.63896$oR5.8950@pd7tw3no>,
"Robert TV" <ducott_99@yahoo.com> wrote:
> > Not enough info :-D. If you want different actions, you can make a hash
> > with references to subs, and use the first letter (perldoc -f substr) to
> > obtain (perldoc -f lc) the sub ref, and execute its sub.
> >
> > But from the above it's really unclear what you want. For example,
> > $condition. Do you want 26 different ones? If you just want to prefix it
> > with caps first letter followed by :, use substr.
> >
> > PS: use strict and use warnings on top of your script. I guess you don't
> > use those...
>
> What I am trying to do is take action based on the first letter of the @rray
> ellement. Ok, forget about the "A:" etc ect. Lets just say I wanted to do
> this ... no @rrays ... just a normal string ...
>
> $mystring = "Grettings fellow programmer";
>
> if (first letter of $mystring eq "G") {
> do this
> } else {
> do that
> }
perldoc -f substr
perldoc -f uc
if (uc(substr($mystring, 0, 1)) uq 'G') {
do_this;
} else {
do_that;
}
Also, see `perldoc -q switch`.
HTH,
Ricky
--
Pukku
------------------------------
Date: Mon, 12 Apr 2004 18:24:45 +0200
From: "PHP2" <gp@nospm.hr>
Subject: how to do a reverse ip lookup of a DNS server ?
Message-Id: <c5efqg$78l$1@ls219.htnet.hr>
how to do a reverse ip lookup of a DNS server ?
I mean when I check server IP that I see all domains connected to this IP on
the server..
http://www.whois.sc/ has same function..
------------------------------
Date: Mon, 12 Apr 2004 13:33:46 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: I cann't scale gif with correctly with perlmagick.
Message-Id: <remorse-4BFA4C.13334612042004@plato.harvard.edu>
In article <2eebf9a.0404120058.59fe98f7@posting.google.com>,
kennyjohn00001@yahoo.com (kenny) wrote:
> eg: first image of animate gif size is 280X 280 scale to 80%. so
> image size now is 224X224.
>
> second image of animate gif size is 150X 150 scale to 80%. so image
> size now is 187.5X187.5. but..... in the pixel, we don't have .5
> pixel. so problem is come. so maybe second image scale to 187X187 or
> 188X188. this situation maybe will leave white dot/blank dot....
I'm pretty sure that, although you can very probably make animated gifs
with different sized components, things will be much easier if all the
images in the animation are the same size.
Perhaps you should try fixing the animated gif to make every frame the
same size?
Ricky
--
Pukku
------------------------------
Date: 12 Apr 2004 09:00:27 -0700
From: anthonysaffer@yahoo.com (Anthony M. Saffer)
Subject: Re: Interacting w/another App on Win32
Message-Id: <ff7f1f07.0404120800.48b98df9@posting.google.com>
"David K. Wall" <dwall@fastmail.fm> wrote in message
>
> perldoc -f system
> perldoc -f exec
>
> Or look in perlop for qx/STRING/ or `STRING` (backticks, not single-quotes).
Thank you very much!
Anthony
------------------------------
Date: Mon, 12 Apr 2004 19:11:03 GMT
From: perl coder <perlcdr@mail.rumania>
Subject: IPC, buffering, and Win32
Message-Id: <bRBec.22505$Lh2.16083@bignews1.bellsouth.net>
I'm trying to run an external program in Windows (with ActivePerl),
using the piped-open method:
open (PIPE, $cmd_line);
while (<PIPE>) {
# process data
}
All is well and good when my code is run from a shell window, but when I
make a shell-less version (it's a Perl/Tk program compiled with the -gui
argument in perlapp), the data becomes buffered, and that really cramps
my style. :-(
I know that you can trick a program to believe it's running on a
terminal using IO::Pty or Expect, but there doesn't seem to be a PPM for
those modules in ActivePerl 5.8! At least I don't see anything at
http://ppm.activestate.com/PPMPackages/zips/8xx-builds-only/Windows/
even though there seems to be compiled versions for Perl 5.6...
Did Perl 5.8 break those modules, or did they forget to compile them, or
are they available somewhere else?
--
No crazy stuff in my email. ;-)
------------------------------
Date: 12 Apr 2004 21:04:01 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <407B043B.A3A65ED4@doe.carleton.ca>
I needed to do some search/replace on some files in-place. I found
many examples of
perl -i.bak -p -e 's/Old/New/'
According to perldoc, -p does this:
while (<>) {
... # your program goes here
} continue {
print or die "-p destination: $!\n";
}
Here, <> assigns a line to $_. If the target of the assignment was an
array @slurp, it would assign the contents of the whole file to
@slurp. I tried to understand what was a "whole file" when multiple
files are specified as arguments. This was in order to understand
how perl recognizes different files so that it can rename the
originals, the case of "-i.bak". I created two files:
File A.txt: File B.txt:
----------- -----------
1 3
2 4
I tweaked the above perl code to:
test.pl
-------
#!/bin/perl -w
my @slurp;
while (@slurp=<>) {
printf "LINE: @slurp"
} continue {
printf "DOG\n" or die "-p destination: $!\n";
}
I ran "test.pl A.txt B.txt" and got:
LINE: 1
2
3
4
5
6
DOG
The cursor then waits under the "D" in DOG until I press ^D.
Since "LINE:" is only printed once, the "while" condition is satisfied
only once, which means that @slurp was given all the text from A.txt
and B.txt in one shot (no file boundaries recognized here).
Conclusion: perl has some other mechanism to recognize the different
files for renaming when using -p.bak.
Now for the confusing part: What is Perl waiting for? Why is the
cursor waiting under the "D" until I press ^D? Why doesn't this
happen when the implied $_ is used instead of @slurp? I can see that
if @slurp comes up empty, "DOG" is printed, and the loop is repeated,
but why isn't "DOG" printed again and again, forever? And why this
hanging only for @slurp?
Thanks for any insight into this. I don't think this is just
pedagogical. I'm quite the novice in Perl, and still getting use to
the fact that I don't know exactly what's going on when I write a
loop -- unlike, for example, when I write in C/C++. There's no black
magic there.
Fred
--
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
------------------------------
Date: Mon, 12 Apr 2004 17:56:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <slrnc7m7ko.5ll.tadmc@magna.augustmail.com>
Fred Ma <fma@doe.carleton.ca> wrote:
> This was in order to understand
> how perl recognizes different files so that it can rename the
> originals, the case of "-i.bak".
> #!/bin/perl -w
> my @slurp;
> while (@slurp=<>) {
Why a while() rather than the more usual foreach() ?
The 1st iteration will read all of the lines from all of the
files named in @ARGV (at which point @ARGV will be empty).
The 2nd iteration will read lines from STDIN since @ARGV is empty.
> Conclusion: perl has some other mechanism to recognize the different
> files for renaming when using -p.bak.
Right you are. See eof(ARGV) in
perldoc -f eof
> Now for the confusing part: What is Perl waiting for?
Some input on STDIN for the 2nd loop iteration.
> Why is the
> cursor waiting under the "D" until I press ^D?
Because you told it to. :-)
> Why doesn't this
> happen when the implied $_ is used instead of @slurp?
Because you eventually get to eof and <> gives you undef, which
is false, so the loop exits at that point.
> I can see that
> if @slurp comes up empty, "DOG" is printed,
> and the loop is repeated,
That is incorrect.
If @slurp comes up empty then the while() condition is false and
the loop should exit, not repeat, and the continue block should
not be executed since the loop is not continuing.
> but why isn't "DOG" printed again and again, forever?
Because @slurp is coming up empty.
> And why this
> hanging only for @slurp?
Your use of while() here has even me confused.
The expression
@slurp=<>
is in scalar context (all booleans are scalar context).
The <> expression is in list context, so it should give "all the lines"
behavior.
> Thanks for any insight into this. I don't think this is just
> pedagogical.
Aha. What is it then that you are actually trying to accomplish?
I cannot guess due to the while(ARRAY) thing.
But I'll bet the last part of eof()'s docs will help you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Apr 2004 09:04:10 -0700
From: eddiejones64@hotmail.com (EddieJ)
Subject: Newbie Question...
Message-Id: <859c7a6b.0404120804.7d254266@posting.google.com>
I'm writing my first perl script and I'm running in to
difficulties as I imagined. What I'm trying to do is
basically scan all the directories and subdirectories
of a drive for powerpoint files, write the full path
and name of the files to an ordinary text file, and
then remove the drive name and colon (eg C:) from the
path and send the output to another text file.
The script I have so far is...
print "Which drive do you want to search? ";
chomp($drive = <STDIN>);
chdir("$drive") || die "Cannot access requested drive";
$outputfile1 = ("%HOMEDRIVE%\\ppfile1.txt");
$outputfile2 = ("%HOMEDRIVE%\\ppfile2.txt");
$outputfile3 = ("%HOMEDRIVE%\\ppfile3.txt");
if (-e $outputfile1) {
unlink ($outputfile1);
}
if (-e $outputfile2) {
unlink ($outputfile2);
}
if (-e $outputfile3) {
unlink ($outputfile3);
}
system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
system ("dir/s/b *.xyz >$outputfile2");
open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
open FILE2, ">$outputfile2" || die "Cannot open file2 $!";
while (defined <FILE1>) {
# print FILE1 $_;
print FILE2 s/^a-zA-Z://;
}
close (FILE1) || die "Cannot close file1 $!";
close (FILE2) || die "Cannot close file2 $!";
But when I run it, the second output file is empty and perl
complains that it cannot close the first outputfile
-----------------------------
Which drive do you want to search? j:
File Not Found
Cannot close file1 Bad file descriptor at powerp.pl line 27.
-------------------------------
The "File Not Found" is from the
"system ("dir/s/b *.xyz >$outputfile2");"
which doesnt bother me since I'm just trying to create an empty
file so that I can open it later to receive the output (without
the C:).
From what I can see though, the open commands aren't working
despite the use of the "die" commands..
So...I'm sure this is very obvious to anyone with experience
of Perl, but (a) what am I doing wrong with the script??? and
(b) is there a more efficient way of doing what I'm trying to
do??. Can you do a recursive directory search in perl without
using the system dir/b/s command, and should I store the output
in an array rather than the first output file....
Thanks in advance....
EJ
------------------------------
Date: Mon, 12 Apr 2004 12:31:05 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie Question...
Message-Id: <20040412121432.X27629@dishwasher.cs.rpi.edu>
On Mon, 12 Apr 2004, EddieJ wrote:
> I'm writing my first perl script and I'm running in to
> difficulties as I imagined. What I'm trying to do is
> basically scan all the directories and subdirectories
> of a drive for powerpoint files, write the full path
> and name of the files to an ordinary text file, and
> then remove the drive name and colon (eg C:) from the
> path and send the output to another text file.
>
> The script I have so far is...
#!perl.exe
use warnings;
use strict;
>
> print "Which drive do you want to search? ";
> chomp($drive = <STDIN>);
> chdir("$drive") || die "Cannot access requested drive";
> $outputfile1 = ("%HOMEDRIVE%\\ppfile1.txt");
> $outputfile2 = ("%HOMEDRIVE%\\ppfile2.txt");
> $outputfile3 = ("%HOMEDRIVE%\\ppfile3.txt");
>
> if (-e $outputfile1) {
> unlink ($outputfile1);
> }
>
> if (-e $outputfile2) {
> unlink ($outputfile2);
> }
>
> if (-e $outputfile3) {
> unlink ($outputfile3);
> }
Why are you bothering with this? If the files exist when you try to open
them for writing, they are automatically clobbered.
> system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
> system ("dir/s/b *.xyz >$outputfile2");
Good checking the return value of the first system(). Bad not checking
the return value of the second system().
> open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
> open FILE2, ">$outputfile2" || die "Cannot open file2 $!";
> while (defined <FILE1>) {
> # print FILE1 $_;
> print FILE2 s/^a-zA-Z://;
> }
What? What exactly are you trying to do here? You're opening two files
for writing, and then trying to read from one of them, and exit the loop
when you can't read any more. This doesn't make sense. You can't read
from FILE1 because you opened FILE1 for writing.
I don't understand what data you're expecting to be in $_. I also don't
understand why you're trying to open these files at all when you already
redirected the output of the system() calls to go to those files.
> close (FILE1) || die "Cannot close file1 $!";
> close (FILE2) || die "Cannot close file2 $!";
>
> But when I run it, the second output file is empty and perl
> complains that it cannot close the first outputfile
>
> -----------------------------
> Which drive do you want to search? j:
> File Not Found
> Cannot close file1 Bad file descriptor at powerp.pl line 27.
> -------------------------------
>
> The "File Not Found" is from the
> "system ("dir/s/b *.xyz >$outputfile2");"
> which doesnt bother me since I'm just trying to create an empty
> file so that I can open it later to receive the output (without
> the C:).
>
> From what I can see though, the open commands aren't working
> despite the use of the "die" commands..
>
>
> So...I'm sure this is very obvious to anyone with experience
> of Perl, but (a) what am I doing wrong with the script??? and
> (b) is there a more efficient way of doing what I'm trying to
> do??. Can you do a recursive directory search in perl without
> using the system dir/b/s command, and should I store the output
> in an array rather than the first output file....
To answer b) "Yes, use File::Find". This is a module that will
recursively scan any directory you give to it. For more info,
perldoc File::Find
#!perl.exe
use strict;
use warnings;
use File::Find;
my $dir = "C:";
my ($out1, $out2);
open $out1, "> output1.txt" or die "Cannot open output1.txt: $!";
open $out2, "> output2.txt" or die "Cannot open output2.txt: $!";
sub wanted {
return unless /\.ppt$/i; #skip non-powerpoint files
print $out1 "$File::Find::name\n"; #print full path to one file
$File::Find::name =~ s/^[a-z]://i; #strip C:
print $out2 "$File::Find::name\n"; #print modified path to other
}
find (\&wanted, $dir); #recursively scan all directories under C:
__END__
Hope this helps
Paul Lalli
------------------------------
Date: Mon, 12 Apr 2004 16:32:50 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Newbie Question...
Message-Id: <Xns94C97FA34E35Fdkwwashere@216.168.3.30>
Please put the subject of your post in the Subject header of your
post. "Newbie Question" is not very informative.
EddieJ <eddiejones64@hotmail.com> wrote:
> So...I'm sure this is very obvious to anyone with experience
> of Perl, but (a) what am I doing wrong with the script???
Using DOS commands when there are easier ways to do much more with
Perl. :-)
> and
> (b) is there a more efficient way of doing what I'm trying to
> do??. Can you do a recursive directory search in perl without
> using the system dir/b/s command,
Yes. See File::Find.
# example untested code
use strict;
use warnings;
use File::Find;
my $drive = 'c';
find(
sub{
if (/\.pp.$/) {
(my $path = $File::Find::name) =~ s/^$drive://;
print "$path\n";
}
},
"$drive:/"
);
> and should I store the output
> in an array rather than the first output file....
I don't know. What are you intending to do with the data after you
collect it?
------------------------------
Date: Mon, 12 Apr 2004 11:35:49 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Newbie Question...
Message-Id: <Ozzec.15$aV.38008@news.uswest.net>
EddieJ wrote:
> So...I'm sure this is very obvious to anyone with experience
> of Perl, but (a) what am I doing wrong with the script??? and
Your most pressing issue is with the open.
system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
The "open" is opening ( > ) $ouptputfile1 for a write, which removes any
data already in that file. You want "<" to read from that file.
For reference:
perldoc perlopentut
> (b) is there a more efficient way of doing what I'm trying to
> do??. Can you do a recursive directory search in perl without
> using the system dir/b/s command, and should I store the output
> in an array rather than the first output file....
Yes and Yes. Take a look at File::Find
http://search.cpan.org/~lbrocard/perl5.005_04/lib/File/Find.pm
Only write it to a file if there's a lot of data, which would use more
memory than your machine can handle. If you can keep the info in an
array, make your modifications to it then write it to disk or do
whatever you need, it'll be much better.
See ya
------------------------------
Date: 12 Apr 2004 16:37:58 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Newbie Question...
Message-Id: <slrnc7lhf7.stu.xx087@smeagol.ncf.ca>
EddieJ <eddiejones64@hotmail.com> wrote:
[...]
> $outputfile1 = ("%HOMEDRIVE%\\ppfile1.txt");
I don't have Perl on a windows box, but you probably want:
my $file = "$ENV{HOMEDRIVE}\\ppfile1.txt";
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Mon, 12 Apr 2004 12:41:20 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie Question...
Message-Id: <20040412123358.C27629@dishwasher.cs.rpi.edu>
On Mon, 12 Apr 2004, EddieJ wrote:
> open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
> open FILE2, ">$outputfile2" || die "Cannot open file2 $!";
BTW, a possible reason your opens are failing is that you're using the
wrong form of 'or'. The two operators 'or' and '||' have the same effect,
but at a different precedence. Specifically, || binds more tightly than
the open operator, so die was never getting called. Your two options are
either:
open FILE1, "> $outputfile1" or die "Cannot open file1: $!";
or
open (FILE1, "> $outputfile") || die ("Cannot open file1: $!");
> while (defined <FILE1>) {
> # print FILE1 $_;
> print FILE2 s/^a-zA-Z://;
> }
In addition to what I said in my last message, it might not be a bad idea
for you to review regular expressions. Printing the result of a
search-and-replace is not going to give you what you think it is for one,
and a-zA-Z doesn't mean what you think it does without being in a
character class.
perldoc perlre
> So...I'm sure this is very obvious to anyone with experience
> of Perl, but (a) what am I doing wrong with the script??? and
> (b) is there a more efficient way of doing what I'm trying to
> do??. Can you do a recursive directory search in perl without
> using the system dir/b/s command, and should I store the output
> in an array rather than the first output file....
>
Reading this one more time, I think I misunderstood you the first time
around. If you don't actually need the "full" pathname (with C:)
attached, remove the lines that deal with the first input file from the
code I posted in the previous message. Instead:
#!perl.exe
use strict;
use warnings;
use File::Find;
my $dir = "C:";
my $out;
open $out, "> output.txt" or die "Cannot open output1.txt: $!";
sub wanted {
return unless /\.ppt$/i; #skip non-powerpoint files
$File::Find::name =~ s/^[a-z]://i; #strip C:
print $out "$File::Find::name\n"; #print modified path to file
}
find (\&wanted, $dir); #recursively scan all directories under C:
__END__
Paul Lalli
------------------------------
Date: Mon, 12 Apr 2004 15:27:52 -0400
From: "Dale" <ssadale@nospam.yahoo.com>
Subject: PERL web addressing
Message-Id: <ItmdncUchaDQc-fdRVn-sQ@inoc.net>
Probably a dumb question but....
I ran across a site that is using an addressing technique that impressed me
and a variation on it could solve a problem I've been working on.
I've been considering setting up a "folder" with a sub-folder representing
each "page". Then I could have a hidden default executable that would
validate user agents and users would have a bit of a time knowing what
language was being used or the server platform. Probably pretty niave but a
thought.
Anyway, the site in question has all of its links and addresses in the form
of blah.com/index.pl/[some folder] There are no page or file type references
visible in either the address bar or status bar and the source code in the
browser is in the same format. I've seen many sites that use a querystring
to reference the requested file and process the request through a script but
never this method.
Thoughts?
Dale
------------------------------
Date: Mon, 12 Apr 2004 10:54:36 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <407abbce$0$24349$58c7af7e@news.kabelfoon.nl>
Tad McClellan wrote:
> Xah Lee <xah@xahlee.org> wrote:
>
>>fuck Perl coders.
>
> The overwhelming majority of Perl coders are men.
>
> You are most bold coming out like that in such a public forum!
Why? Itīs 2004, even 2000 years ago, in many countries, being gay or
bisexual was accepted.
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: Mon, 12 Apr 2004 19:45:06 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <qvkl7054li13oklj8ge14brbcq9hqi7086@4ax.com>
X-Ftn-To: John Bokma
John Bokma <postmaster@castleamber.com> wrote:
>>>fuck Perl coders.
>>
>> The overwhelming majority of Perl coders are men.
>>
>> You are most bold coming out like that in such a public forum!
>
>Why? Itīs 2004, even 2000 years ago, in many countries, being gay or
>bisexual was accepted.
I guess acceptance has nothing to do with it, OP didn't wrote "fuck gay Perl
coders". :-)
--
Matija
------------------------------
Date: Mon, 12 Apr 2004 12:56:59 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <407ad898$0$24357$58c7af7e@news.kabelfoon.nl>
Matija Papec wrote:
> X-Ftn-To: John Bokma
>
> John Bokma <postmaster@castleamber.com> wrote:
>
>>>>fuck Perl coders.
>>>
>>>The overwhelming majority of Perl coders are men.
>>>
>>>You are most bold coming out like that in such a public forum!
>>
>>Why? Itīs 2004, even 2000 years ago, in many countries, being gay or
>>bisexual was accepted.
>
> I guess acceptance has nothing to do with it, OP didn't wrote "fuck gay Perl
> coders". :-)
I agree and but the reply "The overwhelming majority of Perl coders are
men." and Being "most bold" sounded not nice in my ears :-(
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: 12 Apr 2004 14:34:50 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Questions about the Class::Contract module
Message-Id: <slrnc7lvba.n3d.jtc@shell.dimensional.com>
I've begun looking into using the Class::Contract module as, essentially, an
infrastructure for producing object-oriented modules and programs. From
what I've seen so far, there are several advantages to this approach (in
addition to the DBC features - preconditions, invariants, etc. - that it
provides), including: a simple syntax for specifying a class's interface;
a straightforward mechanism for specifying and enforcing whether a
particular attribute or method is public; a simplified process for defining
constructors (for example, an explicit "bless ..." statement is not
required); a simplified method for specifying the attributes of a class.
In short, it appears to me that Class::Contract provides a powerful and
very useful mechanism for implementing an OO Perl program without much of
the tedium and extra work that would be required without the use of such
a module. On the other hand, when I search http://groups.google.com/ for
Class::Contract I see very little discussion of it (only about 28 results).
This leads me to suspect that this module is not used very much.
My questions are:
Is it true that this module is not used very much or are my search results
misleading? (E.e., perhaps discussion, requests for help, etc. for this
module are mainly confined to more closed media, such as mailing lists.)
If it is not used much, for those who have some insights as to why this is
so, would you mind sharing them here?
For those who use or are familiar with Class::Contract - Do you find it
useful for writing well-designed OO modules or applications in Perl?
Have you found it to be of relatively high quality - e.g., few bugs and
reasonable workarounds for any serious bugs? What are the main
disadvantages of using the module?
What other modules and tools have people found to be effective or helpful
for writing OO modules or applications in Perl?
[I thinks this is relevant to both *.modules and *.misc, but if not,
apologies for the crossposting.]
Thanks!
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Mon, 12 Apr 2004 19:50:51 GMT
From: Yoda Pugsley <here@there.com>
Subject: running multiple versions of perl
Message-Id: <Xns94C9A13B64BADheretherecom@65.32.1.6>
I'm new to perl and need to write a script for work. After doing some
research into writing perl scripts (I'm a .net dev), I found that a lot of
the examples I had found did not work. After a lot of head scratching (the
UNIX admins are a lot of help too /sarcasm) I checked the perl version,
5.005_3. Most of the examples are from perl 5.8, hence no workie on
5.0whatever.
Given all of this, I'd like to install my own copy of perl 5.8 in my home
directory. Is that going to interfere with the current 5.0 install? I don't
think I could get the admins to move the whole machine to 5.8, so it has to
be a local kind of thing. I know what might happen if I tried something
like this on a Windows machine, but on UNIX, is it possible?
Thanks,
JH
------------------------------
Date: 12 Apr 2004 11:14:39 -0700
From: nsf470@yahoo.com (pj)
Subject: SOAP:Lite Client - server message passing
Message-Id: <11711ebf.0404121014.39e48fe5@posting.google.com>
Hi,
sends a file
SiteA: client --------------------------------> SiteB: server
<--------------------------------
sends a file
I want to implement something like above using SOAP:Lite. I know a
client can send a file to a server, but can server send a file to a
client? if so, how can this be done? All I know is the return
"message" to send a string message.
I was planning to do something like the following. Each sites has SOAP
client and server.
sends a file
SiteA: client --------------------------------> SiteB: server
server<-------------------------------- client
sends a file
But I am wondering if it can be done with SiteA:client and
SiteB:server.
thanks in advance.
------------------------------
Date: Mon, 12 Apr 2004 23:57:30 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: some sed to perl action...
Message-Id: <20040412235730.72e204b8@asiclindt001>
On 8 Apr 2004 12:40:57 -0700
bringuet@loomissayles.com (Barry Ringuet) wrote:
> eh gday, put together the following dog eviction but don't know how to
> unravel it again... would like to do only in perl but don't know how
> and am not digesting perlre fast enough
> appreciated...
> sed -n '/somestring/,$p' somefile|perl -pi -e
> 's/\f/\n/g,s/\033E//,s/\015//g' > somefile2
$ man s2p
NAME
s2p - Sed to Perl translator
s2p might be of help to you.
Regards,
Thens.
------------------------------
Date: 12 Apr 2004 19:00:38 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: some sed to perl action...
Message-Id: <slrnc7lpqn.stu.xx087@smeagol.ncf.ca>
Barry Ringuet <bringuet@loomissayles.com> wrote:
> eh gday, put together the following dog eviction but don't know how to
> unravel it again... would like to do only in perl but don't know how
> and am not digesting perlre fast enough
> appreciated...
> sed -n '/somestring/,$p' somefile|perl -pi -e
> 's/\f/\n/g,s/\033E//,s/\015//g' > somefile2
perl -ne '
$go=1 if not $go and /somestring/;
s/\f/\n/g, s/\033E//, s/\015//g, print if $go;
' somefile > somefile2
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: 12 Apr 2004 10:14:56 -0700
From: google@milbaugh.com (GreenLight)
Subject: Re: striped name to variable
Message-Id: <c4b60ce1.0404120914.c9dc83a@posting.google.com>
"blnukem" <bill@hotmail.com> wrote in message news:<1Xwec.5948$467.1540351@news4.srv.hcvlny.cv.net>...
> Hi All
>
> How do I strip a word out of a phrase and save the striped part as a
> variable example:
>
> $phrase = "My name is Nick<br>";
> $phrase =~ s/Nick//is;
>
> Now how do I set a new variable that equals the striped part "Nick"
my $stripped = ($phrase =~ s/(Nick)//i);
--
my real address is perl - at - milbaugh - dot - com
------------------------------
Date: 12 Apr 2004 21:34:46 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: striped name to variable
Message-Id: <slrnc7m2rm.mmm.sholden@flexal.cs.usyd.edu.au>
On 12 Apr 2004 10:14:56 -0700, GreenLight <google@milbaugh.com> wrote:
> "blnukem" <bill@hotmail.com> wrote in message news:<1Xwec.5948$467.1540351@news4.srv.hcvlny.cv.net>...
>> Hi All
>>
>> How do I strip a word out of a phrase and save the striped part as a
>> variable example:
>>
>> $phrase = "My name is Nick<br>";
>> $phrase =~ s/Nick//is;
>>
>> Now how do I set a new variable that equals the striped part "Nick"
>
> my $stripped = ($phrase =~ s/(Nick)//i);
You may want to test that.
--
Sam Holden
------------------------------
Date: Mon, 12 Apr 2004 19:00:55 GMT
From: Rob Perkins <rob_perkins@hotmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <2mpl70d727sd1r6und5fqbd78s6fhla1fu@4ax.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
>"Richard Morse" <remorse@partners.org> wrote in message
>news:remorse-41C993.17314006042004@plato.harvard.edu...
>> In article <lt0n60d4k4rv7hukaei12s0tsq2p6btc80@4ax.com>,
>> Rob Perkins <rob_perkins@hotmail.com> wrote:
>>
>> > /(?<!")"(?!")(.*?)(?<!")"(?!")/, on my sample string, produces:
>> >
>> > <>
>> > "quick"
>> > "fox jumped ""over"" the"
>> > </>
>> >
>> > How should I modify the regex to get:
>> > <>
>> > quick
>> > fox jumped ""over"" the
>> > </>
>> >
>> > ...in other words, without the quotes as first and last characters in
>> > the matches?
>>
>> You could add a second and third pass:
>> s/^"//;
>> s/"$//;
>>
>
>Second and third passes? Yuck!
>
>The quotes could be removed in one regex, but in this case the match pattern
>*does not* produce the results the OP claims and so no other processing
>should be necessary.
The match pattern produced the first set of results I listed. I needed
the second set.
>If there are quotation marks at the beginning and end
>of the strings, I would hazard a guess that the OP added them somewhere his
>code.
Nope.
Rob
------------------------------
Date: 12 Apr 2004 14:12:09 -0700
From: fxn@hashref.com (Xavier Noria)
Subject: Re: Why are arrays and hashes this way?
Message-Id: <31a13074.0404121312.7517a568@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x77jwlgvbs.fsf@mail.sysarch.com>...
> then you need to learn some c. there is no easy way to truly nest stuff
> without pointers in c. any tree of mixed structures must use
> pointers.
Yes.
> so now it comes to translating that to perl. how would you
> assign a hash to a scalar slot? currently a hash or an array in a scalar
> context (and this is mostly true in perl4) returns its size. do you make
> a full copy during the assignment? how do you handle looped data? with
> full copies and no references/pointers you can't have data loops. how
> would you pass things around to subs, again with full copies? what does
> it mean to assign an array which has arrays to another array? does it do
> a flattening or a deep copy?
So it wouldn't be technically possible from the start to implement
arrays and hashes with pointers behind the scenes albeit the language
itself hadn't references? That would give surely different semantics
from the user's view. But when data types were defined semantics were
chosen as well (I insist I mean _originally_, not in Perl 5).
I think lists in Lisp have that behaviour. I mean, after
(setq foo (list 0))
(setq bar foo)
(setf (car bar) 1)
foo is (1). I don't mean this is better or worse in any way, just to
give an example of the alternative working in an old language.
My conjecture is:
* Nesting structures was not a requirement in the first versions of
Perl (no guess about the reason).
* Semantics for arrays, hashes, and lists are defined taking the whole
language into account and the fact that they just have to hold
scalars. They end up having the semantics we know, which were
considered to be the best in that context. (If that was the case that
statement would surely be an oversimplification.)
* When Perl 5 arrives compatibility is important, so those semantics
are not changed. In consequence, references are provided as a mean to
nest structures, which is now a requirement.
Does that makes any sense?
-- fxn
------------------------------
Date: 12 Apr 2004 14:18:13 -0700
From: hobbit_hk@hotmail.com (Hobbit HK)
Subject: Re: Writing to STDIN
Message-Id: <22ee5d47.0404121318.6a28fdd1@posting.google.com>
Hmmm........ So if it's such a bad idea and such, how does bash and
other shells write to STDIN when you press TAB to complete your
writing?
Just for my general knowledge :)
------------------------------
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 6390
***************************************