[28475] in Perl-Users-Digest
Perl-Users Digest, Issue: 9839 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 12 18:05:49 2006
Date: Thu, 12 Oct 2006 15:05:05 -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 Thu, 12 Oct 2006 Volume: 10 Number: 9839
Today's topics:
Re: Are indirect DIRHANDLEs closed automatically? xhoster@gmail.com
Re: Are indirect DIRHANDLEs closed automatically? <jl_post@hotmail.com>
beginner trying to use Getopt::Long <mark.leeds@morganstanley.com>
Re: beginner trying to use Getopt::Long <mritty@gmail.com>
Re: beginner trying to use Getopt::Long <serman_d@hotmail.com>
Re: beginner trying to use Getopt::Long <jgibson@mail.arc.nasa.gov>
Re: beginner trying to use Getopt::Long <jgibson@mail.arc.nasa.gov>
Re: Finding uneven file permissions with Perl anno4000@radom.zrz.tu-berlin.de
Re: Firefox Won't Execute My Perl Script <No_4@dsl.pipex.com>
Re: Input into Net::Netmask <m@remove.this.part.rtij.nl>
myspace meets tucows and planetsourcecode? <usenet_daughter@yahoo.com>
Re: Perl scoping questions <jgibson@mail.arc.nasa.gov>
Re: replace variable with same variable <noreply@invalid.net>
Socket error <mdudley@king-cart.com>
Re: Socket error <glex_no-spam@qwest-spam-no.invalid>
Re: Sorting and moving files to dir for DVD burn (at)
Re: Sorting and moving files to dir for DVD burn <mritty@gmail.com>
Re: Sorting and moving files to dir for DVD burn <bik.mido@tiscalinet.it>
Re: Why these original FORTRAN quirks? <a24061@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Oct 2006 18:16:26 GMT
From: xhoster@gmail.com
Subject: Re: Are indirect DIRHANDLEs closed automatically?
Message-Id: <20061012141942.521$zt@newsreader.com>
"jl_post@hotmail.com" <jl_post@hotmail.com> wrote:
> Hi,
>
> I've found in the Camel book (where it discusses the open()
> function) that you can pass it an indirect filehandle as an undefined
> variable, like this:
>
> open(my $fh, ">logfile") or die ...
>
> and Perl will automatically define that variable for you. It goes on
> to say that one advantage of this is that the filehandle will be closed
> automatically when there are no further references to it (typically
> when the variable goes out of scope).
>
> That's nice to know. And "perldoc -f opendir" says that opendir()
> can also take a variable (as an indirect dirhandle).
>
> But neither that perldoc nor the Camel book's documentation of
> opendir() mention if the indirect DIRHANDLE will be closed
> automatically when there are no further references to it.
>
> So my question is: If I write code like this:
>
> opendir(my $dirHandle, '/tmp')
> or die "Cannot open '/tmp': $!\n";
>
> will the DIRHANDLE just opened be closed by the end of $dirHandle's
> scope (presuming there are no other references to it)? I would think
> it does get closed, but I'm unable to find any documentation explicitly
> stating that.
I didn't see it documented, but empirically it does close when it goes
out of scope:
$ strace perl -wle '{opendir(my $dir, "/tmp") or die $!;} sleep 5'
Gives this:
....
open("/tmp", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat64(3, {st_mode=S_IFDIR|S_ISVTX|0777, st_size=20480, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
close(3) = 0
time([1160676995]) = 1160676995
rt_sigprocmask(SIG_BLOCK, [CHLD], [RTMIN], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [RTMIN], NULL, 8) = 0
nanosleep({5, 0}, {5, 0}) = 0
Notice the close(3) happens before the nanosleep, so the directory
is closed before the sleep, i.e. when the block is closed and $dir goes
out of scope
Xho
>
> Thanks for any input.
>
> -- Jean-Luc
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 12 Oct 2006 12:01:39 -0700
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Are indirect DIRHANDLEs closed automatically?
Message-Id: <1160679699.154070.162040@h48g2000cwc.googlegroups.com>
xhoster@gmail.com wrote:
>
> I didn't see it documented, but empirically it does close when it goes
> out of scope:
>
> $ strace perl -wle '{opendir(my $dir, "/tmp") or die $!;} sleep 5'
Thanks, Xho! That was impressive!
And your approach gave me an idea on how to test this using
ActiveState Perl on WinXP: I used FilemonNt (freeware from
http://www.sysinternals.com ) to monitor the perl.exe process to
discover if and when the directory was closed.
While running FilemonNt, I started the Perl "interactive
interpreter" with:
perl -wde 1
Then I typed the following command:
;{ opendir(DIR, '.') or warn $! }
FilemonNt then showed the following eight lines:
perl.exe:3172 OPEN C:\ IS DIRECTORY
perl.exe:3172 OPEN C:\ SUCCESS
perl.exe:3172 CLOSE C:\ SUCCESS
perl.exe:3172 OPEN C:\ SUCCESS
perl.exe:3172 QUERY INFORMATION C:\ SUCCESS
perl.exe:3172 CLOSE C:\ SUCCESS
perl.exe:3172 OPEN C:\ SUCCESS
perl.exe:3172 DIRECTORY C:\ SUCCESS
and when I typed the following:
closedir(DIR);
FilemonNt immediately displayed an additional line:
perl.exe:3172 CLOSE C:\ SUCCESS
But when I typed and executed the following command that uses an
indirect DIRHANDLE:
;{ opendir(my $dir, '.') or warn $! }
FilemonNt displayed all nine of the above lines at once, implying that
the closedir($dir) does happen implicitly, at least when I ran it using
ActiveState Perl on Windows XP.
Again, thanks for your input, Xho. I appreciate it.
-- Jean-Luc
------------------------------
Date: 12 Oct 2006 11:58:40 -0700
From: "markpark" <mark.leeds@morganstanley.com>
Subject: beginner trying to use Getopt::Long
Message-Id: <1160679520.565760.58640@c28g2000cwb.googlegroups.com>
I was hoping that someone could help me. I'm new to the list and I'm at
a job
and kind of under pressure and don't know who else to ask.
I new at perl and I wrote a short program to read values from the
command line and then
just output them into a hash. i've grinded through the documentation
and books and wrote
something but it's not quite working. its close though.
I couldn't find a way to attach files so I've included the code below
and then how one would
run the program with various values at the command line ( actually they
aren't options.
they are required ).
#------------------------------------------------------------------------------------------------------------------------------
#!/ms/dist/perl5/bin/perl5.6
use strict;
use Getopt::Long;
my($DRIVER_FILE,$START_DATE,$END_DATE,$START_TIME,$END_TIME,$CURRENCY,$EXCHANGE,$DATA_DIR,$OUT_FILE);
my %dict= ('driverfile' => \$DRIVER_FILE, 'startdate' => \$START_DATE,
'enddate=' => \$END_DATE, 'starttime=' => \$START_TIME, 'endtime=' =>
\$END_TIME, 'currency' => \$CURRENCY, 'exchange' => \$EXCHANGE,
'datadir' => \$DATA_DIR, 'outfile' => \$OUT_FILE);
GetOptions(\%dict,'driverfile=s','startdate=s','enddate=s','starttime=s','endtime=s','currency=s','exchange=s','datadir=s','outfile=s');
if (!exists($dict{"startdate"}) ) {
die " program requires startdate argument \n";
} elsif (!exists($dict{"enddate"}) ) {
die " program requires enddate argument \n";
} elsif (!exists($dict{"starttime"}) ) {
die " program requires starttime argument \n";
} elsif (!exists($dict{"endtime"}) ) {
die " program requires endtime argument \n";
} elsif (!exists($dict{"currency"}) ) {
die " program requires currency argument \n";
} elsif (!exists($dict{"exchange"}) ) {
die " program requires exchange argument \n";
} elsif (!exists($dict{"datadir"}) ) {
die " program requires datadir argument \n";
} elsif (!exists($dict{"outfile"}) ) {
die " program requires outfile argument \n";
}
# CHECK THAT THE VALUES WERE PUT IN THE HASH CORRECTLY
print"-------------------------------\n";
print "$DRIVER_FILE \n";
print "$START_DATE \n";
print "$END_DATE \n"; # MISSING
print "$START_TIME \n"; # MISSING
print "$END_TIME \n"; # MISSING
print "$CURRENCY \n";
print "$EXCHANGE \n";
print "$DATA_DIR \n";
print "$OUT_FILE \n";
# THE THREE MISSINGS ABOVE ARE THE ONLY ONES THAT SHOW UP BELOW
!!!!!!!!!!!!!
# VERY STRANGE. MAYBE THIS MEANS SOMETHING.
print "-------------------------\n";
while ( my ( $key,$value ) = each %dict ) {
print "$key => $value\n";
}
Thank you very much to whomever would be kind enough to look
at this. I've spent a day and a half on this and I think I can't figure
it out alone.
-------------------------------------------------------------------------------------------------------------------------------------------
sample of how it would be run. it's easier if one puts below in a shell
script so
that typing at command line is minimized.
/u/etlfs/dev/users/leedsmar/res/proj2/perl_src/makedriver.pl
-driverfile=r_driver -startdate=20060120 -enddate=20060130
-starttime=00:00:01 -endtime=00:05:00 -currency=eur/usd.FXEBSLN
-exchange=fxebsln -datadir=/u/etlfs/dev/users/leedsmar/res/proj2/wrk
-outfile=test.dat
------------------------------
Date: 12 Oct 2006 12:32:15 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: beginner trying to use Getopt::Long
Message-Id: <1160681534.877771.219400@b28g2000cwb.googlegroups.com>
markpark wrote:
> I was hoping that someone could help me. I'm new to the list and I'm at
> a job
> and kind of under pressure and don't know who else to ask.
>
> I new at perl and I wrote a short program to read values from the
> command line and then
> just output them into a hash. i've grinded through the documentation
> and books and wrote
> something but it's not quite working. its close though.
>
> I couldn't find a way to attach files so I've included the code below
> and then how one would
> run the program with various values at the command line ( actually they
> aren't options.
> they are required ).
>
>
> #------------------------------------------------------------------------------------------------------------------------------
>
> #!/ms/dist/perl5/bin/perl5.6
>
> use strict;
It's good that you used strict. It's really really bad that you didn't
use warnings...
use warnings;
> use Getopt::Long;
>
> my($DRIVER_FILE,$START_DATE,$END_DATE,$START_TIME,$END_TIME,$CURRENCY,$EXCHANGE,$DATA_DIR,$OUT_FILE);
>
> my %dict= ('driverfile' => \$DRIVER_FILE, 'startdate' => \$START_DATE,
> 'enddate=' => \$END_DATE, 'starttime=' => \$START_TIME, 'endtime=' =>
> \$END_TIME, 'currency' => \$CURRENCY, 'exchange' => \$EXCHANGE,
> 'datadir' => \$DATA_DIR, 'outfile' => \$OUT_FILE);
Youch. Please attempt to format your code to not kill people's eyes:
my %dict= ('driverfile' => \$DRIVER_FILE, 'startdate' => \$START_DATE,
'enddate=' => \$END_DATE, 'starttime=' => \$START_TIME,
'endtime=' => \$END_TIME, 'currency' => \$CURRENCY,
'exchange' => \$EXCHANGE, 'datadir' => \$DATA_DIR,
'outfile' => \$OUT_FILE);
Now take a look at the third, fourth, and fifth keys in that hash. Did
you notice the extra = in there? They don't belong....
> GetOptions(\%dict,'driverfile=s','startdate=s','enddate=s','starttime=s','endtime=s','currency=s','exchange=s','datadir=s','outfile=s');
Okay, so once you fix the three erroneous equals signs, this will put
each option in the variable that the corresponding key in the hash
references. For example, the option for driverfile will go into the
variable $DRIVER_FILE.
Any options specified in this list that do NOT have keys in the hash
(which means enddate, starttime, and endtime, because those keys were
not in the hash (because of the extra =)) will be added, and their
values will be the option values specified on the command line.
> if (!exists($dict{"startdate"}) ) {
> die " program requires startdate argument \n";
> } elsif (!exists($dict{"enddate"}) ) {
> die " program requires enddate argument \n";
> } elsif (!exists($dict{"starttime"}) ) {
> die " program requires starttime argument \n";
> } elsif (!exists($dict{"endtime"}) ) {
> die " program requires endtime argument \n";
> } elsif (!exists($dict{"currency"}) ) {
> die " program requires currency argument \n";
> } elsif (!exists($dict{"exchange"}) ) {
> die " program requires exchange argument \n";
> } elsif (!exists($dict{"datadir"}) ) {
> die " program requires datadir argument \n";
> } elsif (!exists($dict{"outfile"}) ) {
> die " program requires outfile argument \n";
> }
First of all, this is a revolting amount of code duplication. Shorten
it to:
for my $opt (qw/startdate enddate starttime endtime currency exchange
datadir outfile/) {
die " program requires $opt argument \n" unless exists
$dict{$opt};
}
Second, however, it's not doing what you think it's doing. It's
checking to see if these keys exist in the hash. We already know they
do - your code put them in there. What you *meant* to do was check to
see if the variables referenced by those keys' values are still
undefined:
for my $opt (qw/startdate enddate starttime endtime currency exchange
datadir outfile/) {
die " program requires $opt argument \n" unless defined
${$dict{$opt}};
}
> # CHECK THAT THE VALUES WERE PUT IN THE HASH CORRECTLY
>
> print"-------------------------------\n";
>
> print "$DRIVER_FILE \n";
> print "$START_DATE \n";
> print "$END_DATE \n"; # MISSING
> print "$START_TIME \n"; # MISSING
> print "$END_TIME \n"; # MISSING
Those three are missing because the hash did not include keys
corresponding to them. Again, fix the = problem.
> print "$CURRENCY \n";
> print "$EXCHANGE \n";
> print "$DATA_DIR \n";
> print "$OUT_FILE \n";
>
> # THE THREE MISSINGS ABOVE ARE THE ONLY ONES THAT SHOW UP BELOW
> !!!!!!!!!!!!!
> # VERY STRANGE. MAYBE THIS MEANS SOMETHING.
>
> print "-------------------------\n";
>
> while ( my ( $key,$value ) = each %dict ) {
> print "$key => $value\n";
> }
Didn't you notice that this output, for example, both of:
enddate => 20060130
enddate= => SCALAR(0x14d100)
The first one is the actual option the user entered on the command
line. The second one is the key/value pair you put into your hash to
begin with.
Now, once you've fixed your = problem, again you're not checking the
right thing. You don't want to print the value of the hash. You know
what that is - it's a reference to a scalar variable. You want to
check the contents of that scalar variable that's being referenced:
while (my ($key, $value) = each %dict) {
print "$key => ${$value}\n";
}
> Thank you very much to whomever would be kind enough to look
> at this. I've spent a day and a half on this and I think I can't figure
> it out alone.
>
> -------------------------------------------------------------------------------------------------------------------------------------------
> sample of how it would be run. it's easier if one puts below in a shell
> script so
> that typing at command line is minimized.
>
> /u/etlfs/dev/users/leedsmar/res/proj2/perl_src/makedriver.pl
> -driverfile=r_driver -startdate=20060120 -enddate=20060130
> -starttime=00:00:01 -endtime=00:05:00 -currency=eur/usd.FXEBSLN
> -exchange=fxebsln -datadir=/u/etlfs/dev/users/leedsmar/res/proj2/wrk
> -outfile=test.dat
Be very careful doing this. If by some chance you also had (for
example) -o, -u, -t, -f, -i, -l, and -e as valid options, I believe
calling your options with only one dash would set each of those
options, rather than 'outfile'. Use two dashes to eliminate the
ambiguity.
Paul Lalli
------------------------------
Date: 12 Oct 2006 13:16:06 -0700
From: "Serman D." <serman_d@hotmail.com>
Subject: Re: beginner trying to use Getopt::Long
Message-Id: <1160684166.892264.153740@h48g2000cwc.googlegroups.com>
I suggest you start by simply throwing away the hash and be sure to
name the variables and arguments 1-to-1 (e.g. "$start_time" and
"--start_time", both in lowercase with underscore). Note use of double
minus signs when arguments are non-single-letter.
Consider also adding a =pod section at the end of file and use
pod2usage (from Pod::Usage) instead of die.
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
my (
$driver_file, $start_date, $end_date, $start_time, $end_time,
$currency, $exchange, $data_dir, $out_file
);
GetOptions(
'driver_file=s' => \$driver_file,
'start_date=i' => \$start_date,
'end_date=i' => \$end_date,
'start_time=s' => \$start_time,
'end_time=s' => \$end_time,
'currency=s' => \$currency,
'exchange=s' => \$exchange,
'data_dir=s' => \$data_dir,
'out_file=s' => \$out_file,
);
if ( !defined( $start_date ) ) {
die " program requires start_date argument \n";
}
elsif ( !defined( $end_date ) ) {
die " program requires enddate argument \n";
}
elsif ( !defined( $start_time ) ) {
die " program requires starttime argument \n";
}
elsif ( !defined($end_time) ) {
die " program requires endtime argument \n";
}
elsif ( !defined($currency) ) {
die " program requires currency argument \n";
}
elsif ( !defined($exchange) ) {
die " program requires exchange argument \n";
}
elsif ( !defined($data_dir) ) {
die " program requires datadir argument \n";
}
elsif ( !defined($out_file) ) {
die " program requires outfile argument \n";
}
print "-------------------------------\n";
print "$driver_file \n";
print "$start_date \n";
print "$end_date \n";
print "$start_time \n";
print "$end_time \n";
print "$currency \n";
print "$exchange \n";
print "$data_dir \n";
print "$out_file \n";
__END__
$ perl makedriver.pl --driver_file=r_driver --start_date=20060120
--end_date=20060130 --start_time=00:00:01 --end_time=00:05:00
--currency=eur/usd.FXEBSLN --exchange=fxebsln
--data_dir=/u/etlfs/dev/users/leedsmar/res/proj2/wrk
--out_file=test.dat
-------------------------------
r_driver
20060120
20060130
00:00:01
00:05:00
eur/usd.FXEBSLN
fxebsln
/u/etlfs/dev/users/leedsmar/res/proj2/wrk
test.dat
__
Serman D.
------------------------------
Date: Thu, 12 Oct 2006 13:36:22 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: beginner trying to use Getopt::Long
Message-Id: <121020061336224415%jgibson@mail.arc.nasa.gov>
In article <1160679520.565760.58640@c28g2000cwb.googlegroups.com>,
markpark <mark.leeds@morganstanley.com> wrote:
> I was hoping that someone could help me. I'm new to the list and I'm at
> a job
> and kind of under pressure and don't know who else to ask.
>
> I new at perl and I wrote a short program to read values from the
> command line and then
> just output them into a hash. i've grinded through the documentation
> and books and wrote
> something but it's not quite working. its close though.
>
> I couldn't find a way to attach files so I've included the code below
> and then how one would
> run the program with various values at the command line ( actually they
> aren't options.
> they are required ).
>
>
>
> #------------------------------------------------------------------------------
> ------------------------------------------------
>
> #!/ms/dist/perl5/bin/perl5.6
>
> use strict;
> use Getopt::Long;
>
>
> my($DRIVER_FILE,$START_DATE,$END_DATE,$START_TIME,$END_TIME,$CURRENCY,$EXCHANG
> E,$DATA_DIR,$OUT_FILE);
>
> my %dict= ('driverfile' => \$DRIVER_FILE, 'startdate' => \$START_DATE,
> 'enddate=' => \$END_DATE, 'starttime=' => \$START_TIME, 'endtime=' =>
> \$END_TIME, 'currency' => \$CURRENCY, 'exchange' => \$EXCHANGE,
> 'datadir' => \$DATA_DIR, 'outfile' => \$OUT_FILE);
>
>
> GetOptions(\%dict,'driverfile=s','startdate=s','enddate=s','starttime=s','endt
> ime=s','currency=s','exchange=s','datadir=s','outfile=s');
>
> if (!exists($dict{"startdate"}) ) {
> die " program requires startdate argument \n";
[rest snipped]
Your use of GetOptions is incorrect. Command line values are placed in
$DRIVER_FILE, etc, not the %dict hash. Read 'perldoc Getopt::Long';
use strict;
use warnings;
use Getopt::Long;
my($DRIVER_FILE,$START_DATE);
GetOptions(
'driverfile=s' => \$DRIVER_FILE,
'startdate=s' => \$START_DATE
);
if ( ! defined $START_DATE ) {
die " program requires startdate argument \n";
}
print "$DRIVER_FILE\n";
print "$START_DATE \n";
__END__
Please post short-as-possible programs. Your problem can be
demonstrated with only one variable.
------------------------------
Date: Thu, 12 Oct 2006 14:37:10 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: beginner trying to use Getopt::Long
Message-Id: <121020061437104291%jgibson@mail.arc.nasa.gov>
In article <1160681534.877771.219400@b28g2000cwb.googlegroups.com>,
Paul Lalli <mritty@gmail.com> wrote:
> markpark wrote:
> > I was hoping that someone could help me. I'm new to the list and I'm at
> > a job
> > and kind of under pressure and don't know who else to ask.
[snip]
> > sample of how it would be run. it's easier if one puts below in a shell
> > script so
> > that typing at command line is minimized.
> >
> > /u/etlfs/dev/users/leedsmar/res/proj2/perl_src/makedriver.pl
> > -driverfile=r_driver -startdate=20060120 -enddate=20060130
> > -starttime=00:00:01 -endtime=00:05:00 -currency=eur/usd.FXEBSLN
> > -exchange=fxebsln -datadir=/u/etlfs/dev/users/leedsmar/res/proj2/wrk
> > -outfile=test.dat
>
> Be very careful doing this. If by some chance you also had (for
> example) -o, -u, -t, -f, -i, -l, and -e as valid options, I believe
> calling your options with only one dash would set each of those
> options, rather than 'outfile'. Use two dashes to eliminate the
> ambiguity.
That is not the default behavior. Getopt::Long will only accept
"bundled" single-character options if
Getopt::Long::Configure("bundling") has been called and
Getopt::Long::Configure("bundling_override") has _not_ been called.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 12 Oct 2006 19:53:35 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Finding uneven file permissions with Perl
Message-Id: <4p7kpvFhk685U1@news.dfncis.de>
<UnixMaestro@gmail.com> wrote in comp.lang.perl.misc:
> Paul,
> thanks for the help, it is greatly appreciated.
>
> as a test, I used:
> #!/usr/bin/perl -w
> use File::Find;
> no warnings File::Find;
>
> find(\&getFiles, @ARGV);
> sub getFiles {
> my $mode = (stat $File::Find::name)[2];
> my $user = ($mode / 8**2) % 8;
> my $group = ($mode / 8) % 8;
> my $other = $mode % 8;
> printf "$File::Find::name has permissions of:" . $user . $group .
> $other . "\n";
> }
>
> I'll tinker with the uneven file permissions later on tonight, but so
> far, this works.
>
> I started jotting down file permissions I should not see and ended up
> with 18 so far that I don't want to see (not including SUID, SGID or
> the sticky bit). I'm thinking that my first assessment of comparing
> the digits to be nebulous. It might be better spent looking for
> patterns I don't want to see, like [4-7][1-3][0-7]. If you have any
> recommendations that would make this faster (besides not doing it) I
> would like to hear them.
I doubt you have to worry about that kind of speed, after all you
have at least one disk access per file you check.
If it matters, generate the unwanted permissions beforehand and collect
them in a hash (or array), there aren't that many (untested):
my %bad;
for my $u ( 0 .. 7 ) {
for my $g ( $u + 1 .. 7 ) {
for my $o ( $g + 1 .. 7 ) {
$bad{ oct "$u$g$o"} = 1;
}
}
}
Then check a file or handle $file with
if ( $bad{ (stat $file)[ 2] & PERM_MASK} ) {
# uneven permissions
}
Anno
------------------------------
Date: Thu, 12 Oct 2006 20:06:22 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Firefox Won't Execute My Perl Script
Message-Id: <qYCdnVBQJreyD7PYRVnyhA@pipex.net>
steve.ziring@gmail.com wrote:
> I have a perl script that executes successfully in MSIE, but Firefox
> prompts me to open or save the same file. I can not get the Perl file
> to execute in Firefox.
Do you actually mean that you can't get Firefox to start running the
script for you?
Are you actually expecting the browser to download a file, called
xxx.pl, and get it run by a perl executable installed on your system?
Yes - I think IE will run downloaded scripts for you. Firefox won't
(it's got more sense than to do it). When such a script runs it runs under
your account with all of your access and so can do anything you can do on
the system, whether you actually wish it to.
Executing arbitrary code from the Internet in such a manner is a *big*
security risk. You shouldn't do it.
If you actually mean something else then please give further details.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Thu, 12 Oct 2006 21:35:31 +0200
From: Martijn Lievaart <m@remove.this.part.rtij.nl>
Subject: Re: Input into Net::Netmask
Message-Id: <pan.2006.10.12.19.35.31.89221@remove.this.part.rtij.nl>
On Wed, 11 Oct 2006 18:17:44 -0500, Tad McClellan wrote:
> Don't use the 3-part for loop, it is easy to introduce an Off By One
> Error, as you have seen:
>
> foreach my $i ( 0 .. $#blocks )
Or:
$i=0;
for (@blocks) {
$hashBlock{$vlans[$i++]} = new Net::Netmask($_);
}
M4
--
Redundancy is a great way to introduce more single points of failure.
------------------------------
Date: 12 Oct 2006 14:20:47 -0700
From: "Mad Scientist Jr" <usenet_daughter@yahoo.com>
Subject: myspace meets tucows and planetsourcecode?
Message-Id: <1160688047.149968.307550@c28g2000cwb.googlegroups.com>
Is there a myspace type site that is a place for programmers to post
their apps for people to download? It would have to be user friendly
like tucows but allow a programmer to create their own home page where
they can post their apps (including open source if they wish). People
can network and link to each other, rate other's apps, and search for
code by platform/language/keyword/most popular, etc. It would support
EVERY platform imaginable, from 8-bit atari code to .NET and Java apps.
Does anything like this exist?
------------------------------
Date: Thu, 12 Oct 2006 13:14:57 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Perl scoping questions
Message-Id: <121020061314577298%jgibson@mail.arc.nasa.gov>
In article <1160659486.058458.324960@m73g2000cwd.googlegroups.com>,
grocery_stocker <cdalten@gmail.com> wrote:
> Given
>
> #!/usr/bin/perl
>
> $x = 1000;
>
> sub g() {
> $x=1;
> print "$x\n";
> }
>
> g();
>
> print "$x\n";
>
> produces
> $./bi.pl
> 1
> 1
>
>
> How can $x in g modify $x=1000 (which is global) when the variable
> isn't passed by reference (or pointers)? To do the same thing in C, I
> would do like the following:
>
> include <stdio.h>
>
> int x = 1000;
>
> int g (int *p) {
> *p=1;
> printf("%d\n",*p);
> return 0;
> }
>
> int main(void) {
>
> g(&x);
> printf("%d\n",x);
>
> return 0;
> }
>
> $gcc -Wshadow -Wall bi.c -o bi
> $./bi
> 1
> 1
If I were re-writing your Perl program in C, I would produce the
following:
#include <stdio.h>
int x = 1000;
void g () {
x = 1;
printf("%d\n",x);
}
int main(void) {
g();
printf("%d\n",x);
return 0;
}
which has exactly the same behavior and output:
1
1
------------------------------
Date: Thu, 12 Oct 2006 18:22:59 GMT
From: Ala Qumsieh <noreply@invalid.net>
Subject: Re: replace variable with same variable
Message-Id: <7KvXg.6265$NE6.306@newssvr11.news.prodigy.com>
Bart Van der Donck wrote:
> Paul Lalli wrote:
>
>> Bart Van der Donck wrote:
>> > $line=~s/PILOT_INC=[2-8],/$& NGHBR_SRCH_MODE = 0,/g;
>>
>> Please don't do that. Using the $&, $', and $` variables slow down ALL
>> regular expressions in the entire program even if you only use any of
>> them once.
>>
>> $line =~ /(PILOT_INC=[2-8])/$1 NGHBR_SRCH_MODE = 0,/g;
>
> Any idea how many milliseconds will be lost ? :-)
It could be much longer than that, and I learned this the hard way.
I wrote a Perl/Tk script at work that used to take ~2 minutes to load all
the necessary data before invoking the GUI. At some point, I needed to add
support for some functions that are defined in a stand-alone Perl Module.
All of a sudden, this caused my script to take ~30 minutes to load, and I
was really stumped for the longest time trying to figure out why. Through
the process of elimination, I traced it all back to a single statement:
use aModule;
it turns out that aModule was using $& inside, slowing down everything else,
even though I was not yet using any functions inside aModule.pm!
Avoid $&, except perhaps in simple throw-away scripts (or Perl Golf :)
--Ala
------------------------------
Date: Thu, 12 Oct 2006 19:11:04 GMT
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Socket error
Message-Id: <452E9332.994BFD02@king-cart.com>
I have a short script to use with the cron to get an ip address so if
the nameserver is down, I will still have a recent ip and the scripts
that communicate with that host do not crash.
#! /usr/bin/perl
use Socket;
$host = 'theurl.com'; #this is NOT the real url I am using
$ip = inet_ntoa(inet_aton($host));
if ($ip =~ /\d+\.\d+\.\d+\.\d+/) {
open (FILE,">/usr/home/kingcart/cgi-bin/host.ip");
print FILE $ip;
close FILE;
}
If I run it by hand from the command prompt, it works every time. When I
put it in the cron, it fails about 80% of the time with the following
error:
Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at
/usr/home/kingcart/cgi-bin/gethost.pl line 5.
Any ideas why it fails usually when run by the cron, but works fine when
run manually. What does this error mean?
Thanks,
Marshall
------------------------------
Date: Thu, 12 Oct 2006 16:31:28 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Socket error
Message-Id: <452eb3c8$0$600$815e3792@news.qwest.net>
Marshall Dudley wrote:
> I have a short script to use with the cron to get an ip address so if
> the nameserver is down, I will still have a recent ip and the scripts
> that communicate with that host do not crash.
A "recent IP"??? The IP for the host changes frequently?
>
> #! /usr/bin/perl
>
> use Socket;
> $host = 'theurl.com'; #this is NOT the real url I am using
^^^
Why are you trying to get an IP of a URL?
> $ip = inet_ntoa(inet_aton($host));
> if ($ip =~ /\d+\.\d+\.\d+\.\d+/) {
> open (FILE,">/usr/home/kingcart/cgi-bin/host.ip");
or die "Can't open host.ip: $!"
It probably doesn't belong in your cgi-bin directory.
> print FILE $ip;
> close FILE;
> }
>
> If I run it by hand from the command prompt, it works every time. When I
> put it in the cron, it fails about 80% of the time with the following
> error:
>
> Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at
> /usr/home/kingcart/cgi-bin/gethost.pl line 5.
>
> Any ideas why it fails usually when run by the cron, but works fine when
> run manually. What does this error mean?
Using a search engine and searching on that error led me to:
http://aspn.activestate.com/ASPN/Mail/Message/pdk/2233385
The whole idea seems like a poor hack though. Suggestions:
o Fix nameserver or use a more reliable one.
o Get all of the possible IPs and iterate through them, when the
nameserver doesn't resolve it.
o Add the IP to your hosts file.
------------------------------
Date: Thu, 12 Oct 2006 14:14:50 -0400
From: at <"romorris(at)"@bellsouth.net>
Subject: Re: Sorting and moving files to dir for DVD burn
Message-Id: <nCvXg.23683$vi3.22752@bignews3.bellsouth.net>
at wrote:
> Michele Dondi wrote:
>> On 11 Oct 2006 19:27:27 -0700, "romorris@bellsouth.net"
>> <romorris@bellsouth.net> wrote:
>>
>>
>>> Im sure someone done this, probally for MP3's, and knows how to do it
>>> in such a simple fashion with perl, so I have to ask this:
>>>
>>> I have a quite few files (~230), all different sizes ( 2megs~200megs )
>>> all in one directory. All files are compressed(.Z).
>>>
>>> What I want to do is somehow sort and move these into seperate
>>> directories filling each as close to 4 gigs as possible. This way I can
>>>
>>
>> Notoriously, this is a mathematically hard problem, precisely the
>> "knapsack problem". However for more pointers you may look into the
>> following PM thread:
>>
>> http://perlmonks.org/?node_id=546968
>>
>> which BTW has some "suspiscious" similarities with this message
>> itself...
>>
>>
>> HTH,
>> Michele
>>
> Michele;
> "suspicious similarities" is Right! I guess there are actually others
> looking for the same thing. Funny thing was after wading though
> messages about "file splitting" I had found a handful of other similar
> requests, all with no answers, or going in the wrong direction.
>
> Thanks for this link. This is exactly what I'm trying to do, but too
> bad I don't know more about Perl.
>
> The link also gives better search terms than I was using, lets see
> where I can go from there.
>
> thanks!
>
> -Rob
Thanks for the link, I found some code but not at all good with perl
yet. This works great, but only creates the list. Could anyone tell me
how i can modify this it move the files it organizes into
subdirectories? thanks!
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
#use constant QUOTA => 4.7 * 2**30;
use constant QUOTA => 4.7 * 2**30;
sub wanted ();
@ARGV = grep { -d or !warn "Not a directory: `$_'\n" } @ARGV;
die "Usage: $0 <dir> [<dirs>]\n" unless @ARGV;
my ($size,$cnt)=0;
find { no_chdir => 1,
wanted => \&wanted }, @ARGV;
sub wanted () {
return unless -f;
print 'List ', $cnt++, ':' unless $size;
my $sz = -s _;
warn "Too big single item: `$_'\n" and
return if $sz >= QUOTA;
my $newsz=$size + $sz;
if ($newsz<QUOTA) {
print;
$size=$newsz;
} else {
print '';
$size=0;
wanted; # "redo"
}
}
------------------------------
Date: 12 Oct 2006 11:54:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Sorting and moving files to dir for DVD burn
Message-Id: <1160679243.969085.18260@k70g2000cwa.googlegroups.com>
at wrote:
> This works great, but only creates the list. Could anyone tell me
> how i can modify this it move the files it organizes into
> subdirectories? thanks!
>
> #!/usr/bin/perl -l
>
> use strict;
> use warnings;
> use File::Find;
use File::Copy;
> #use constant QUOTA => 4.7 * 2**30;
> use constant QUOTA => 4.7 * 2**30;
>
> sub wanted ();
>
> @ARGV = grep { -d or !warn "Not a directory: `$_'\n" } @ARGV;
> die "Usage: $0 <dir> [<dirs>]\n" unless @ARGV;
>
> my ($size,$cnt)=0;
> find { no_chdir => 1,
> wanted => \&wanted }, @ARGV;
my $basedir = "path/to/base/directory/";
my $dir;
> sub wanted () {
> return unless -f;
> print 'List ', $cnt++, ':' unless $size;
# [eliminate line above, and replace with:]
if ($size == 0) {
$cnt++;
print "List $cnt: ";
$dir = "$basedir/$cnt";
mkdir $dir unless -d $dir; # see footnote
}
> my $sz = -s _;
> warn "Too big single item: `$_'\n" and
> return if $sz >= QUOTA;
> my $newsz=$size + $sz;
> if ($newsz<QUOTA) {
> print;
> $size=$newsz;
move $_, $dir or warn "Could not move $_ to $dir: $!";
> } else {
> print '';
> $size=0;
> wanted; # "redo"
> }
> }
Footnote: This line is a class race condition, and is general a very
bad thing. However, in this self-contained example, I do not forsee it
causing a problem. If you have other processes which may also be
trying to create directories of the same name as this process, you may
run into problems.
Paul Lalli
------------------------------
Date: 12 Oct 2006 22:36:54 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Sorting and moving files to dir for DVD burn
Message-Id: <kp9ti29f28va0hb5qh50k8qgg0kq4q672b@4ax.com>
On Thu, 12 Oct 2006 14:14:50 -0400, at <"romorris(at)"@bellsouth.net>
wrote:
>use constant QUOTA => 4.7 * 2**30;
Haha! Don't be fooled by the hype. I thought so too. But it turned out
to be 4.7 * 10**3...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 12 Oct 2006 19:06:01 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Why these original FORTRAN quirks?
Message-Id: <9pc204-iqn.ln1@news.ducksburg.com>
On 2006-10-12, Scott Lurndal <scott@slp53.sl.home> wrote:
> "Ancient_Hacker" <grg2@comcast.net> writes:
>>Anybody have any idea why good old FORTRAN had these quirks:
>>
>>
>>(1) three-way arithmetic IF
>
> Simple translation to a "compare" machine instruction. two
> branches to the < > case and fall through to the = case.
Perl's sort and Java's comparators (and no doubt other languages'
analogous features) use three-way comparisons and are extremely useful
that way.
------------------------------
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 9839
***************************************