[24048] in Perl-Users-Digest
Perl-Users Digest, Issue: 6245 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 11 06:05:50 2004
Date: Thu, 11 Mar 2004 03:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 11 Mar 2004 Volume: 10 Number: 6245
Today's topics:
Archive::Zip and symbolic link <thens@NOSPAMti.com>
Re: Archive::Zip and symbolic link (Anno Siegel)
Re: Deleting a folder recursively <krahnj@acm.org>
Extracting directories in a path - TMBABWTDI <news@lawshouse.org>
Re: Extracting directories in a path - TMBABWTDI <tore@aursand.no>
Re: Extracting directories in a path - TMBABWTDI <fifo@despammed.com>
Re: Extracting directories in a path - TMBABWTDI <krahnj@acm.org>
Re: Extracting directories in a path - TMBABWTDI (Anno Siegel)
Re: Extracting directories in a path - TMBABWTDI (Anno Siegel)
Re: Extracting directories in a path - TMBABWTDI (Anno Siegel)
login to a website problem in Perl (S Domadia)
Re: Ordering large files (in perl?) (Oeln)
Re: Ordering large files (in perl?) (Oeln)
Re: Ordering large files (in perl?) (Oeln)
Re: Ordering large files (in perl?) (Anno Siegel)
Signal handlng oddness (Vorxion)
Re: using an assoc. array as a 'set' <bik.mido@tiscalinet.it>
Re: using an assoc. array as a 'set' <tassilo.parseval@rwth-aachen.de>
Re: using an assoc. array as a 'set' (Anno Siegel)
Re: variable initialization question <krahnj@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Mar 2004 12:27:56 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Archive::Zip and symbolic link
Message-Id: <20040311122756.6c34dcf5.thens@NOSPAMti.com>
Hi,
Iam trying to use Archive::Zip to create zip files from a disk tree. Iam
seeing this problem when I try to include a symbolic link into the
archive.
If fatals out saying " The stat preceding -l _ wasn't an lstat at
/usr/local/lib/perl5/site_perl/5.6.0/Archive/Zip.pm line 2882".
The documentation of the module says "
addFile( $fileName [, $newName ] )
Append a member whose data comes from an external file,
returning the member or undef. The member will have its
file name set to the name of the external file, and its
desiredCompressionMethod set to COMPRESSION_DEFLATED.
The file attributes and last modification time will be
set from the file.
If the name given does not represent a readable plain
file or symbolic link, undef will be returned.
The text mode bit will be set if the contents appears to
be text (as returned by the `-T' perl operator).
The optional second argument sets the internal file name
to something different than the given $fileName.
".
Am I missing something here. Iam just trying to mimic the 'zip -y'
feature. Is there any other way I can do it. The advantage with this
module is that it works in linux as well. That is the reason I prefer to
use this instead of the zip/unzip utility.
Thanks in Advance.
Regards,
Thens.
------------------------------
Date: 11 Mar 2004 10:57:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Archive::Zip and symbolic link
Message-Id: <c2pgmh$dna$5@mamenchi.zrz.TU-Berlin.DE>
Thens <thens@NOSPAMti.com> wrote in comp.lang.perl.misc:
> Hi,
>
> Iam trying to use Archive::Zip to create zip files from a disk tree. Iam
> seeing this problem when I try to include a symbolic link into the
> archive.
>
> If fatals out saying " The stat preceding -l _ wasn't an lstat at
> /usr/local/lib/perl5/site_perl/5.6.0/Archive/Zip.pm line 2882".
Show your code. Archive::Zip compresses data from a symlink just fine
for me.
Anno
------------------------------
Date: Thu, 11 Mar 2004 08:30:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Deleting a folder recursively
Message-Id: <4050237C.D9ACFFEB@acm.org>
Shabam wrote:
>
> I'm currently using the following function to delete entire directories
> including all content in it. However it often fails out on me and gives me
> the message "Failed to remove foldername". Can someone take a look at this
> and tell me what I can do to stop that? Basically I want to duplicate the
> system function "rm -rf foldername" with perl. I'm running this in the
> command line btw.
use warnings;
use strict;
> sub dir_del {
>
> my $direc = $_[0];
> my (@dirs,$new_dir);
>
> opendir(DIR,$direc);
You should *ALWAYS* verify that opendir was successfull.
> @dirs = grep {!(/^\./) && -d "$direc/$_" } readdir(DIR);
> close DIR;
To close a directory handle opened with opendir() you have to use
closedir().
> @dirs = sort(@dirs);
>
> opendir (DIR, "$direc");
You should *ALWAYS* verify that opendir was successfull. Why the
quotes, you had it correct the first time? Why open and close the same
directory twice when once is enough?
> @files = grep {!(/^\./) && -f "$direc/$_"} readdir(DIR);
Why are you skipping all files and directories that start with a dot?
Where do you declare @files?
> close (DIR);
To close a directory handle opened with opendir() you have to use
closedir().
> foreach $file(@files) {
> unlink("$direc/$file") || print "Failed to remove $direc/$file";
> }
>
> for $new_dir(0..$#dirs) {
> &dir_del("$direc/$dirs[$new_dir]");
> rmdir("$direc/$dirs[$new_dir]") || print "Failed to remove
> $direc/$dirs[$new_dir]";
> }
> }
I would do it like this (untested):
sub dir_del {
my $direc = $_[0];
opendir my $DIR, $direc or die "Failed to open $direc: $!";
my @files = map "$direc/$_", grep !/^\.\.?$/, readdir $DIR;
closedir $DIR;
for my $file ( @files ) {
if ( -d $file ) {
dir_del( $file );
rmdir $file or warn "Failed to remove $file: $!";
}
else {
unlink $file or warn "Failed to remove $file: $!";
}
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 11 Mar 2004 08:43:30 +0000
From: "Henry Law" <news@lawshouse.org>
Subject: Extracting directories in a path - TMBABWTDI
Message-Id: <pan.2004.03.11.08.43.30.485589@lawshouse.org>
(There must be a better way to do it)
I have a path statement of the form "/dir1/dir2/dir3" and I want to
separate the directories and subdirectories into an array. "split" works
well except that the leading delimiter causes a null value to be entered
into the first position of the array. The following code is the best I
have been able to do to remove the leading slash but the separate
statement strikes me as horribly inelegant; can someone suggest a neater
method?
#! /usr/bin/perl
use strict;
use warnings;
my $path="/a/b/c";
my @nodes = split (/\//, $path);
print "Bad:" . join(',',@nodes) . "\n";
$path =~ s/^\///;
@nodes = split (/\//,$path);
print "Good:" . join(',',@nodes) . "\n";
The results of running this are:
Bad:,a,b,c
Good:a,b,c
Other comments on my perl style are also welcome; there's such a huge
difference between kludging chunks of stuff that works and writing neat
code.
------------------------------
Date: Thu, 11 Mar 2004 10:32:32 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <pan.2004.03.11.09.29.25.230842@aursand.no>
On Thu, 11 Mar 2004 08:43:30 +0000, Henry Law wrote:
> The following code is the best I
> have been able to do to remove the leading slash but the separate
> statement strikes me as horribly inelegant; can someone suggest a neater
> method?
I really think that your latter solution is quite neat;
my $path = '/a/b/c';
$path =~ s,^/,,; # Removing leading '/'
$path =~ s,/$,,; # Removing trailing '/'
my @dirs = join( ',', $path );
What's wrong with it?
--
Tore Aursand <tore@aursand.no>
"Scientists are complaining that the new "Dinosaur" movie shows
dinosaurs with lemurs, who didn't evolve for another million years.
They're afraid the movie will give kids a mistaken impression. What
about the fact that the dinosaurs are singing and dancing?" -- Jay
Leno
------------------------------
Date: Thu, 11 Mar 2004 09:40:55 +0000
From: fifo <fifo@despammed.com>
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <20040311094051.GB8513@fleece>
At 2004-03-11 08:43 +0000, Henry Law wrote:
> I have a path statement of the form "/dir1/dir2/dir3" and I want to
> separate the directories and subdirectories into an array. "split" works
> well except that the leading delimiter causes a null value to be entered
> into the first position of the array. The following code is the best I
> have been able to do to remove the leading slash but the separate
> statement strikes me as horribly inelegant; can someone suggest a neater
> method?
>
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> my $path="/a/b/c";
> my @nodes = split (/\//, $path);
> print "Bad:" . join(',',@nodes) . "\n";
>
> $path =~ s/^\///;
> @nodes = split (/\//,$path);
> print "Good:" . join(',',@nodes) . "\n";
>
> The results of running this are:
>
> Bad:,a,b,c
> Good:a,b,c
>
Not sure if it's really any better, but you could something like
$path = '/a/b//c/d';
@nodes = map { $_ or () } split '/', $path;
print join ',', @nodes;
__END__
a,b,c,d
which also handles consecutive slashes correctly.
------------------------------
Date: Thu, 11 Mar 2004 09:53:25 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <405036F0.98624AA@acm.org>
Henry Law wrote:
>
> (There must be a better way to do it)
>
> I have a path statement of the form "/dir1/dir2/dir3" and I want to
> separate the directories and subdirectories into an array. "split" works
> well except that the leading delimiter causes a null value to be entered
> into the first position of the array. The following code is the best I
> have been able to do to remove the leading slash but the separate
> statement strikes me as horribly inelegant; can someone suggest a neater
> method?
>
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> my $path="/a/b/c";
> my @nodes = split (/\//, $path);
> print "Bad:" . join(',',@nodes) . "\n";
>
> $path =~ s/^\///;
> @nodes = split (/\//,$path);
> print "Good:" . join(',',@nodes) . "\n";
>
> The results of running this are:
>
> Bad:,a,b,c
> Good:a,b,c
>
> Other comments on my perl style are also welcome; there's such a huge
> difference between kludging chunks of stuff that works and writing neat
> code.
Instead of removing the stuff you don't want you should extract the
stuff you do want.
@nodes = $path =~ m|[^/]+|;
John
--
use Perl;
program
fulfillment
------------------------------
Date: 11 Mar 2004 10:00:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <c2pdc8$dna$1@mamenchi.zrz.TU-Berlin.DE>
Henry Law <news@lawshouse.org> wrote in comp.lang.perl.misc:
> (There must be a better way to do it)
>
> I have a path statement of the form "/dir1/dir2/dir3" and I want to
> separate the directories and subdirectories into an array. "split" works
> well except that the leading delimiter causes a null value to be entered
> into the first position of the array. The following code is the best I
> have been able to do to remove the leading slash but the separate
> statement strikes me as horribly inelegant; can someone suggest a neater
> method?
When split() doesn't work quite right, remember Randal's Rule: Use
split when you know what to throw away, use pattern matching if you
know what to keep. Saying what to keep:
my @nodes = m!([^/]+)!g;
Since you asked for it, some comments about your code. It's fine,
generally, the comments are minor points.
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> my $path="/a/b/c";
Single quotes are preferred when there is no interpolation in a string.
> my @nodes = split (/\//, $path);
Use a different delimiter when a "/" is appears in the pattern: "m!/!".
> print "Bad:" . join(',',@nodes) . "\n";
>
> $path =~ s/^\///;
> @nodes = split (/\//,$path);
> print "Good:" . join(',',@nodes) . "\n";
Blanks after ":" and "," wouldn't hurt.
> The results of running this are:
>
> Bad:,a,b,c
> Good:a,b,c
>
> Other comments on my perl style are also welcome; there's such a huge
> difference between kludging chunks of stuff that works and writing neat
> code.
Anno
------------------------------
Date: 11 Mar 2004 10:07:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <c2pdpe$dna$2@mamenchi.zrz.TU-Berlin.DE>
fifo <fifo@despammed.com> wrote in comp.lang.perl.misc:
> At 2004-03-11 08:43 +0000, Henry Law wrote:
> > I have a path statement of the form "/dir1/dir2/dir3" and I want to
> > separate the directories and subdirectories into an array. "split" works
> > well except that the leading delimiter causes a null value to be entered
> > into the first position of the array. The following code is the best I
> > have been able to do to remove the leading slash but the separate
> > statement strikes me as horribly inelegant; can someone suggest a neater
> > method?
> >
> > #! /usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > my $path="/a/b/c";
> > my @nodes = split (/\//, $path);
> > print "Bad:" . join(',',@nodes) . "\n";
> >
> > $path =~ s/^\///;
> > @nodes = split (/\//,$path);
> > print "Good:" . join(',',@nodes) . "\n";
> >
> > The results of running this are:
> >
> > Bad:,a,b,c
> > Good:a,b,c
> >
>
> Not sure if it's really any better, but you could something like
>
> $path = '/a/b//c/d';
> @nodes = map { $_ or () } split '/', $path;
That's a job for grep, not map. Also, it will drop nodes named "0".
Third, split() takes a regex as the first argument. That a string is
accepted is no reason to write it as such when you have a choice. So:
@nodes = grep length, split m!/!, $path; # untested
Anno
------------------------------
Date: 11 Mar 2004 10:09:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Extracting directories in a path - TMBABWTDI
Message-Id: <c2pds9$dna$3@mamenchi.zrz.TU-Berlin.DE>
John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> Henry Law wrote:
> Instead of removing the stuff you don't want you should extract the
> stuff you do want.
>
> @nodes = $path =~ m|[^/]+|;
That needs a /g.
Anno
------------------------------
Date: 11 Mar 2004 02:36:07 -0800
From: sangita_sjtr@yahoo.co.in (S Domadia)
Subject: login to a website problem in Perl
Message-Id: <4c5b8d9e.0403110236.4bb06dc4@posting.google.com>
Hi,
i am developing an application using perl which connects to a website
then login to that site using some username and password.But i am
facing problem as i am not able to login b'coz after login method is
called it's not able to call post method as a response.I tried many
things to make my code working but no one is working.
please help me if you have some idea about it.My application is using
WWW::mechanize package to connect to website if you know any other
better package to connect and login to website please do inform me.
My code is like this:
use WWW::Mechanize;
use HTML::TokeParser;
use diagnostics;
my $browser = WWW::Mechanize->new;
$url="http://www.websitename.com"; # i am using www.investors.com as
a websitename
$user="username";
$pass="password";
$resp1=$browser->get($url);
print "looking at: ", $browser->uri, "\n";
#print $resp1->content;
# print $browser->res->content;
#
$browser->form("forLogIn");
$browser->set_fields(
"htmUserName" => $user,
"htmPassword" => $pass,
);
$browser->click();
print "looking at: ", $browser->uri, "\n";
print $browser->res->content;
open STDOUT,">>ibd.html" or die "can't open$!";
thanks for any suggestions you can provide.
s domadia.
------------------------------
Date: 10 Mar 2004 21:35:00 -0800
From: ohmy9od@yahoo.com (Oeln)
Subject: Re: Ordering large files (in perl?)
Message-Id: <ffde43bc.0403102135.c9066d6@posting.google.com>
Brad Baxter <bmb@ginger.libs.uga.edu> wrote in message news:<Pine.A41.4.58.0403082104460.14578@ginger.libs.uga.edu>...
> On Mon, 8 Mar 2004, Oeln wrote:
> >
> > One idea I came upon implied that exec(sort) would be a good option.
> > I'd imagine like exec(sort INFILE -o OUTFILE); but I'm not certain, or
> > clear on the other options it offers. Is that good enough by itself
> > for large files? I get the impression there is a way to output to a
> > group of temp files, and then 'integrate' them into one file, etc.
> > etc.
> >
>
> Following is an example of what I've done:
>
> system( 'sort', '-T', '/tmp', '-o', $index_temp, $index_temp );
>
> (Note, I _want_ the output to go to the same file. Maybe you don't.)
>
> That is, using system()--not exec()--run the unix sort command. As for
> options, see (unix) man sort. The unix sort does the temp file
> integration process you describe. At least, that's my understanding.
>
> What if something goes wrong? See perldoc -f system.
>
> Regards,
>
> brad
I get this impression, too. I've looked over the info page in fedora
on this, and I get the feeling this is the option to go with.
I've got exec("sort -u $infile -o $oufile"); and it's working. I guess
the issue with exec() is that it only gives back 'false' if it fails,
i.e., only if the command itself is non-existent. In this case, if
I've got exec("sort -u $infile -o $outfile") or die("Issue executing
command. $!"; or whatever instead, isn't it identical? It's not my
intent to be irritating, I only want to 'get it'. ;)
- Oeln
------------------------------
Date: 10 Mar 2004 21:45:30 -0800
From: ohmy9od@yahoo.com (Oeln)
Subject: Re: Ordering large files (in perl?)
Message-Id: <ffde43bc.0403102145.6c1deb42@posting.google.com>
ctcgag@hotmail.com wrote in message news:<20040309133348.553$fg@newsreader.com>...
> ohmy9od@yahoo.com (Oeln) wrote:
> > I've got a large file in which there is one word on each line. I've
> > got to output each word it includes to a new file, in order. I've
> > currently got the following:
> >
> > @order = <INFILE>;
> > @ordered = sort(@order);
> >
> > foreach $o (@ordered) {
> > print OUTFILE "$o";
> > }
> >
> > In general this is working fine; but if I've got to open a larger file
> > (over 1gb, for example, or even 10 gb..whatever) it fails.
> >
> > I've found this issue being gone over to an extent; but the
> > information is not clear to me. I've got a few ideas on how to get
> > this to work (for instance, if I could get one word out of the infile
> > at a time and insert it to the outfile, in order in the first place;
> > but I'd imagine this would be incredibly inefficient).
>
> Yes, it would be incredibly inefficient.
>
I'd imagine. ;)
> > One idea I came upon implied that exec(sort) would be a good option.
> > I'd imagine like exec(sort INFILE -o OUTFILE); but I'm not certain, or
> > clear on the other options it offers.
>
> This is just using Perl to invoke the system sort utility. While this is
> an excellent idea, it doesn't really have much to do with Perl. You will
> have to look into your systems sort command.
>
> > Is that good enough by itself
> > for large files? I get the impression there is a way to output to a
> > group of temp files, and then 'integrate' them into one file, etc.
> > etc.
>
> Most unix-like systems' sort command will do this automatically if they
> need to. They usually write these files to the /tmp drive, so either make
> sure /tmp is large enough, or tell it to put them somewhere else (usually
> the -T switch).
>
> I wish there were a way to tell it to gzip those temp files, so that you
> could sort files larger than the available disk, but as far as I can tell,
> there isn't.
>
It'd be a nice idea, certainly.
> > I guess what I'm looking for is either guidance to further info on
> > this, or example code. I'd like to 'get' what's going on tho either
> > way, though. I'm interested in the learning experience, too - not only
> > in getting it to work.
> >
> > I'm on fedora linux/perl 5.8.3 installed. I've only got 128mb on here,
> > which I imagine is on of my issues..
>
> Be aware of the Locale settings you operate under, as they cause a lot of
> head scratching with "sort".
>
> Xho
I've got to look further into that - I've got no clue what the implication is..
- Oeln
------------------------------
Date: 10 Mar 2004 22:00:58 -0800
From: ohmy9od@yahoo.com (Oeln)
Subject: Re: Ordering large files (in perl?)
Message-Id: <ffde43bc.0403102200.15ece154@posting.google.com>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in message news:<090320041322458099%jgibson@mail.arc.nasa.gov>...
> In article <ffde43bc.0403081722.6fdc2988@posting.google.com>, Oeln
> <ohmy9od@yahoo.com> wrote:
>
> > I've got a large file in which there is one word on each line. I've
> > got to output each word it includes to a new file, in order. I've
> > currently got the following:
> >
> > @order = <INFILE>;
> > @ordered = sort(@order);
> >
> > foreach $o (@ordered) {
> > print OUTFILE "$o";
> > }
> >
> > In general this is working fine; but if I've got to open a larger file
> > (over 1gb, for example, or even 10 gb..whatever) it fails.
> >
> > I've found this issue being gone over to an extent; but the
> > information is not clear to me. I've got a few ideas on how to get
> > this to work (for instance, if I could get one word out of the infile
> > at a time and insert it to the outfile, in order in the first place;
> > but I'd imagine this would be incredibly inefficient).
>
> Yes. Do not reinvent the wheel. If you are on linux, use the sort
> command. 'man sort'.
>
> >
> > One idea I came upon implied that exec(sort) would be a good option.
> > I'd imagine like exec(sort INFILE -o OUTFILE); but I'm not certain, or
> > clear on the other options it offers. Is that good enough by itself
> > for large files? I get the impression there is a way to output to a
> > group of temp files, and then 'integrate' them into one file, etc.
> > etc.
>
> Try 'system("sort infile -o outfile"). The exec command won't return
> execution to your program, probably not what you want.
On looking further into this, I guess it isn't only that exec() only
fails if the command itself is non-existent. I guess it won't wait for
the exec() to complete, either? I'm not overly clear on this, only
cause with exec() I've not gotten the impression this is the case.
I'll continue looking for info on it (if nothing else I'm gonna look
for an example of why one would ever go with exec instead) - for now
I've got:
@order = ("sort", "-u", "$infile", "-o", "$oufile"); system(@order);
> If you have one word per line, that should be all you need. Try it from
> the command line and see if it does what you want, then run with it. I
> am sure you have better things to worry about than implementing a merge
> sort method. You might want '-b' option to sort to ignore leading
> whitespace, -i to ignore non-ascii characters, and -f to use
> case-insensitive sorting.
>
Thank you for the info.
- Oeln
------------------------------
Date: 11 Mar 2004 10:31:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Ordering large files (in perl?)
Message-Id: <c2pf5h$dna$4@mamenchi.zrz.TU-Berlin.DE>
Oeln <ohmy9od@yahoo.com> wrote in comp.lang.perl.misc:
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote in message
> news:<Pine.A41.4.58.0403082104460.14578@ginger.libs.uga.edu>...
> > On Mon, 8 Mar 2004, Oeln wrote:
> > >
> > > One idea I came upon implied that exec(sort) would be a good option.
> > > I'd imagine like exec(sort INFILE -o OUTFILE); but I'm not certain, or
> > > clear on the other options it offers. Is that good enough by itself
> > > for large files? I get the impression there is a way to output to a
> > > group of temp files, and then 'integrate' them into one file, etc.
> > > etc.
> > >
> >
> > Following is an example of what I've done:
> >
> > system( 'sort', '-T', '/tmp', '-o', $index_temp, $index_temp );
> >
> > (Note, I _want_ the output to go to the same file. Maybe you don't.)
> >
> > That is, using system()--not exec()--run the unix sort command. As for
> > options, see (unix) man sort. The unix sort does the temp file
> > integration process you describe. At least, that's my understanding.
> >
> > What if something goes wrong? See perldoc -f system.
> >
> > Regards,
> >
> > brad
>
> I get this impression, too. I've looked over the info page in fedora
> on this, and I get the feeling this is the option to go with.
>
> I've got exec("sort -u $infile -o $oufile"); and it's working. I guess
> the issue with exec() is that it only gives back 'false' if it fails,
> i.e., only if the command itself is non-existent.
It only ever *returns* if if fails. If "exec" is able to start the
program you name, that's the last thing you see of it, never mind if
the program eventually succeeds or fails.
> In this case, if
> I've got exec("sort -u $infile -o $outfile") or die("Issue executing
> command. $!"; or whatever instead, isn't it identical? It's not my
> intent to be irritating, I only want to 'get it'. ;)
Read "perldoc -f system" and "perldoc -f exec", it's all written up
there. No reason to assume one of us can do a better job out of hand.
If you have specific questions, ask.
Anno
------------------------------
Date: 11 Mar 2004 01:16:53 -0500
From: vorxion@knockingshopofthemind.com (Vorxion)
Subject: Signal handlng oddness
Message-Id: <40500455$1_1@news.iglou.com>
I've noticed that signal handling is vastly improved in 5.8.0 and higher.
The docs actually say 5.7.3, I believe.
At any rate, I have the following:
$SIG{TSTP} = \&suspend;
##### Handle suspend signal.
sub suspend {
${sin}->blocking(1) if defined(${sin});;
$SIG{TSTP}='DEFAULT';
fl_log("Suspended by signal.") if ${log} ne 'off';
kill(TSTP,$$);
${sin}->blocking(0)if defined(${sin});
$SIG{TSTP} = \&suspend;
return;
}
Under Solaris 5.7 with perl 5.8.0, this works as I expect it to. It logs the
trap and suspends the process.
Under Solaris 5.7 with perl 5.6.1, this sets off a recursive loop of the
signal handler. No problem, it should under 5.6.1.
The problem came under Cobalt Linux with 5.8.3, when it also set off a
recursive loop of the signal handler, despite having the most recent perl
in use. Any ideas as to why this would happen differently on Linux as
opposed to Solaris?
Barring that, is there a better way to achieve what I'm doing?
--
Vorxion - Member of The Vortexa Elite
------------------------------
Date: Thu, 11 Mar 2004 08:49:53 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: using an assoc. array as a 'set'
Message-Id: <5350501ibgnjbkr9pq1iau30n7lb9l7coi@4ax.com>
On 10 Mar 2004 14:07:57 -0800, ixtahdoom@yahoo.com (ixtahdoom) wrote:
>Simply because I want to use an assoc. array as a set, i don't care
>about the value, only the key. Is there a way to do something like
Speaking of this, I've felt some times that in Perl, notwithstanding
it's complexity and richness, there's something missing, probably more
conceptually than practically.
Hashes implement the concept of finitary functions, so that they can
be used, disregarding the values, as sets, possibly in a more concrete
form by means of some OO trickery.
Also, by a good choice of values assigned to keys, they can be used to
implement other structures, as multisets and so on.
However the feeling that I have is that (mostly) in terms of "UI"
there *may* be more primitive "objects" that implement sets and hashes
are/can be built in terms of these.
Of course, even provided that (some) people agree with me, how one
would go about to integrate new syntax for these "sets" consistently
is beyond my imagination!
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 11 Mar 2004 09:09:25 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: using an assoc. array as a 'set'
Message-Id: <c2pac5$n1b$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Michele Dondi:
> On 10 Mar 2004 14:07:57 -0800, ixtahdoom@yahoo.com (ixtahdoom) wrote:
>
>>Simply because I want to use an assoc. array as a set, i don't care
>>about the value, only the key. Is there a way to do something like
>
> Speaking of this, I've felt some times that in Perl, notwithstanding
> it's complexity and richness, there's something missing, probably more
> conceptually than practically.
>
> Hashes implement the concept of finitary functions, so that they can
> be used, disregarding the values, as sets, possibly in a more concrete
> form by means of some OO trickery.
>
> Also, by a good choice of values assigned to keys, they can be used to
> implement other structures, as multisets and so on.
>
> However the feeling that I have is that (mostly) in terms of "UI"
> there *may* be more primitive "objects" that implement sets and hashes
> are/can be built in terms of these.
>
> Of course, even provided that (some) people agree with me, how one
> would go about to integrate new syntax for these "sets" consistently
> is beyond my imagination!
I suppose it should be done on top of simple hashes. Note that this is
already possible right now with the help of tied hashes. With a simple
FETCH { $_[0]->EXISTS($_[1]) }
you can just write
if ($h{key}) {
and this will return true even if $h{key} is undefined (but existant).
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: 11 Mar 2004 09:33:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using an assoc. array as a 'set'
Message-Id: <c2pbou$cia$1@mamenchi.zrz.TU-Berlin.DE>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 10 Mar 2004 14:07:57 -0800, ixtahdoom@yahoo.com (ixtahdoom) wrote:
>
> >Simply because I want to use an assoc. array as a set, i don't care
> >about the value, only the key. Is there a way to do something like
>
> Speaking of this, I've felt some times that in Perl, notwithstanding
> it's complexity and richness, there's something missing, probably more
> conceptually than practically.
>
> Hashes implement the concept of finitary functions, so that they can
> be used, disregarding the values, as sets, possibly in a more concrete
> form by means of some OO trickery.
>
> Also, by a good choice of values assigned to keys, they can be used to
> implement other structures, as multisets and so on.
>
> However the feeling that I have is that (mostly) in terms of "UI"
> there *may* be more primitive "objects" that implement sets and hashes
> are/can be built in terms of these.
Mathematics goes that way. Starting from sets, "ordered pairs" can
be defined. Then mappings, the mathematical counterparts of hashes,
are defined as certain sets of ordered pairs.
> Of course, even provided that (some) people agree with me, how one
> would go about to integrate new syntax for these "sets" consistently
> is beyond my imagination!
The mathematical model doesn't work well in a direct computer
implementation (sadly, I might add, it's a powerful model). That is
because the set as the base of the mathematical model is not well
suited for a primitive data structure on standard machines. Lists
are easy, but they depend on sequence and can have multiple elements,
they aren't sets. Perhaps when quantum computing makes the
implementation of sets a snap and voids all efficiency considerations
we shall see the BOURBAKI computing language :)
That said, Perl 6 will have pairs (but not sets) as a primitive, and
hashes will be based on pairs.
Anno
------------------------------
Date: Thu, 11 Mar 2004 07:51:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: variable initialization question
Message-Id: <40501A41.233382A5@acm.org>
Anno Siegel wrote:
>
> John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> > Alexander Stremitzer wrote:
> > >
> > > I found that the following statement only initializes the first variable.
> > > my ($a,$b,$c) = 0;
> > > A way that works is:
> > > my ($a,$b,$c) = (0,0,0);
> > >
> > > Is there a simpler way to initialize all variables with the same value 0 ?
> >
> > my ($a,$b,$c) = (0) x 3;
>
> $_ = 0 for my ( $a, $b, $c);
Or:
map $_ = 0, my ( $a, $b, $c );
John
--
use Perl;
program
fulfillment
------------------------------
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 6245
***************************************