[19496] in Perl-Users-Digest
Perl-Users Digest, Issue: 1691 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 4 14:10:26 2001
Date: Tue, 4 Sep 2001 11:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999627010-v10-i1691@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 4 Sep 2001 Volume: 10 Number: 1691
Today's topics:
Re: pl or not pl, that is the question (Randal L. Schwartz)
Re: Recommendations for a PERL editor (Tad McClellan)
Re: Recommendations for a PERL editor <tinamue@zedat.fu-berlin.de>
Re: references, slices, voodoo <stumo@bigfoot.com>
Re: references, slices, voodoo <jasper@guideguide.com>
Shell Scripts vs. Perl Scripts <wolfh@master.sm.go.dlr.de>
Re: Shell Scripts vs. Perl Scripts (Tad McClellan)
Re: Shell Scripts vs. Perl Scripts <info@fruiture.de>
Re: weird kind of eof <bart.lateur@skynet.be>
Re: weird kind of eof <bart@nijlen.com>
Re: Which language better <jfontain@winealley.com>
Why doesn't this regex work? (Benoit Gauthier)
Re: Why doesn't this regex work? <jasper@guideguide.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 04 Sep 2001 06:28:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: pl or not pl, that is the question
Message-Id: <m1ofor84rc.fsf@halfdome.holdit.com>
>>>>> "David" == David Combs <dkcombs@panix.com> writes:
David> I like to keep the extensions on.
David> So I can run a .sh-script like this:
David> ls -Aslt > ls.dn
David> egrep '\.mod$' ls.dn > mod.dn
David> egrep '\.prj$' ls.dn > prj.dn
David> egrep '\.man$' ls.dn > man.dn
David> egrep '\.1$' ls.dn > 1.dn
David> egrep '\.ps$' ls.dn > ps.dn
David> egrep '\.lib$' ls.dn > lib.dn
David> egrep '\.loc$|\.locDKC$|\.locS$|\.locTOOLS$' ls.dn > loc.dn
David> egrep '\.awk$|\.nawk$' ls.dn > awk.dn
David> egrep '\.hlp$' ls.dn > hlp.dn
David> egrep '\.txt$' ls.dn > txt.dn
David> egrep '\.out1$' ls.dn > out1.dn
David> egrep '\.out$' ls.dn > out.dn
David> egrep '\.nam$' ls.dn > nam.dn
David> egrep 'kep$' ls.dn > kep.dn
David> egrep '\.dat$' ls.dn > dat.dn
David> egrep '\.doc$' ls.dn > doc.dn
David> egrep '\.xrf$' ls.dn > xrf.dn
David> egrep '\.aux$' ls.dn > aux.dn
David> egrep '\.dif$' ls.dn > dif.dn
David> egrep '\.ex$' ls.dn > ex.dn
David> egrep '\.sed$' ls.dn > sed.dn
David> egrep '\.pl$' ls.dn > pl.dn
David> egrep '\.pm$' ls.dn > pm.dn
David> egrep '\.html$' ls.dn > html.dn
David> egrep '\.htm$' ls.dn > htm.dn
David> egrep '\.source$' ls.dn > source.dn
David> egrep '\.el$' ls.dn > el.dn
David> egrep '\.sh$' ls.dn > sh.dn
David> egrep '\.gz$' ls.dn > gz.dn
David> egrep '\.Z$' ls.dn > Z.dn
David> Sure helps me keep track of what I have,
David> and how recently I've changed it.
Oh, *really*? You need extensions to do that? Why not just this:
file * | sed -n '/perl commands/s/:.*//p' >perl-scripts-here
Works fine for me. No extensions required.
Oh, did you want a Perl solution?
use File::Find;
use File::MMagic;
my $mm = File::MMagic->new;
my @search = @ARGV;
@search = qw(.) unless @search;
find sub {
return if -d $_ or -l $_;
my $type = $mm->checktype_filename($_);
next unless $type =~ /executable \S+\/perl script/;
print "$File::Find::name: $type\n";
}, @search;
There. Prints just the perl scripts, and it's pure Perl. And
it's not looking at the extensions, it's looking at the contents,
just like the O/S is smart enough to do.
(This is from <http://www.stonehenge.com/merlyn/UnixReview/col36.html>
if you want to read more about it.)
Extensions for scripts are *not needed*. Please stop it.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 04 Sep 2001 14:33:29 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Recommendations for a PERL editor
Message-Id: <slrn9p9mf3.qbl.tadmc@tadmc26.august.net>
Harri J Haataja <hhaataja@melkki.cs.Helsinki.FI> wrote:
>Kurt Stephens wrote:
>>"RoJo" <rojo@mindspring.com> wrote in message
>>news:3b926160.358347636@news.mindspring.com...
>>>
>>> I'm new to PERL. I keep getting "The page cannot be displayed" when I
>>> use Windows 2000's Notepad to edit my scripts.
[snip line endings stuff]
>Most frequently seen and definitely the most cryptic one I've seen is
>that if the #! path doesn't include any arguments and is trailed by a
>CR, you'll get "file not found" IIRC. Anyway, you can guess it after
>you see it and fix it once.
>What makes it funny is that #!/usr/bin/perl
>breaks but #!/usr/bin/perl -w doesn't =)
That is not funny at all if you understand how processing of
shebang lines happens:
1) determine which processor to feed the file to.
2) pass everything after the processor-identifying part
as arguments to the processor.
With "#!/usr/bin/perl\r\n" it determines in step 1 that the
processor's name is "/usr/bin/perl\r". You get "file not found"
when there is not a file with that name.
With "#!/usr/bin/perl -w\r\n", step 1 works fine (it stops
at whitespace), and step 2 passes "-w\r" as an argument to perl,
and _perl_ Does The Right Thing.
When you add a switch, it is perl rather than the OS that
gets to deal with the Carriage Return.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Sep 2001 16:47:07 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Recommendations for a PERL editor
Message-Id: <9n30ib$548uc$1@fu-berlin.de>
Tad McClellan <tadmc@augustmail.com> wrote:
> With "#!/usr/bin/perl\r\n" it determines in step 1 that the
> processor's name is "/usr/bin/perl\r". You get "file not found"
> when there is not a file with that name.
> With "#!/usr/bin/perl -w\r\n", step 1 works fine (it stops
> at whitespace), and step 2 passes "-w\r" as an argument to perl,
> and _perl_ Does The Right Thing.
wouldn't it be clever if webserver-admins, ISPs just create
a "/usr/bin/perl\r" binary additionally? they would never
again have problems with people loading their script up
and asking why it doesn't work...
just kidding =)
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Tue, 4 Sep 2001 15:30:35 +0100
From: "Stuart Moore" <stumo@bigfoot.com>
Subject: Re: references, slices, voodoo
Message-Id: <5y5l7.770$zi3.384429@news2-win.server.ntlworld.com>
Jasper McCrea <jasper@guideguide.com> wrote in message
news:3B94AED2.698A3CF@guideguide.com...
> Walter Hafner wrote:
> >
> > What I don't understand:
> >
> > abigail writes:
> >
> > > Note that the stupid 'unless $i == $j' no longer appears in modern
> > > editions of the FAQ.
> >
> > why "stupid"?
> >
> > -Walter
>
> I suppose because the test isn't much faster than the swap. Quick
> benchmark showed that a swap was only 1/5 as fast as the test, so if the
> array has more than twice as many elements that are different than are
> the same (likely), it's a waste of time to do the test every time, when
> you may as well swap.
The test is $i==$j - i.e. the element generated randomly is the one you've
currently targetted, so you'd be setting $a[1,1] = $a[1,1]
It doesn't test if the swap is useless because the two are the same (i.e.
$a[1]=1;$a[2]=1; $a[1,2]=$a[2,1];) So in fact, the test prevents a swap for on
average 1/n of the swap attempts, of which there are n, i.e. it prevents on
average one swap per run. I ought to be able to work out at what stage the swap
ceases to save time, but I cant be bothered...
Just out of interest, is anyone able to comment on whether this technique
produces results as random as
my @flag = ();
my @newarray = ();
for (my $i = @array; --$i; $i){
do{
my $j = int rand (@array);
} while $flag[$j];
$newarray[$j] = $array[$i];
}
Code isn't very nice and also very inefficient, but seems to me to be more
random, as each permutation would have equal chance - not sure that's the case
for the other one.
------------------------------
Date: Tue, 04 Sep 2001 18:24:01 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: references, slices, voodoo
Message-Id: <3B950E31.3CB06C68@guideguide.com>
Stuart Moore wrote:
>
> Jasper McCrea <jasper@guideguide.com> wrote in message
> news:3B94AED2.698A3CF@guideguide.com...
> > Walter Hafner wrote:
> > >
> > > What I don't understand:
> > >
> > > abigail writes:
> > >
> > > > Note that the stupid 'unless $i == $j' no longer appears in modern
> > > > editions of the FAQ.
> > >
> > > why "stupid"?
> > >
> > > -Walter
> >
> > I suppose because the test isn't much faster than the swap. Quick
> > benchmark showed that a swap was only 1/5 as fast as the test, so if the
> > array has more than twice as many elements that are different than are
> > the same (likely), it's a waste of time to do the test every time, when
> > you may as well swap.
>
> The test is $i==$j - i.e. the element generated randomly is the one you've
> currently targetted, so you'd be setting $a[1,1] = $a[1,1]
Jeez, I had hoped that no one would notice what an imbecile I am, and
point out my ludicrous mistake here, but since they have, I'd better try
to compensate...(by showing how stupid I am again?)
> It doesn't test if the swap is useless because the two are the same (i.e.
> $a[1]=1;$a[2]=1; $a[1,2]=$a[2,1];) So in fact, the test prevents a swap for on
> average 1/n of the swap attempts, of which there are n, i.e. it prevents on
> average one swap per run. I ought to be able to work out at what stage the swap
> ceases to save time, but I cant be bothered...
>
> Just out of interest, is anyone able to comment on whether this technique
> produces results as random as
>
> my @flag = ();
> my @newarray = ();
> for (my $i = @array; --$i; $i){
> do{
> my $j = int rand (@array);
> } while $flag[$j];
> $newarray[$j] = $array[$i];
> }
>
> Code isn't very nice and also very inefficient, but seems to me to be more
> random, as each permutation would have equal chance - not sure that's the case
> for the other one.
Yes, I thought this (that FY would give results of dubious randomosity),
too. Because of the way the FY shuffle works, you seem to often get a
high proportion of the elements staying where they were. I sort of
assumed this was because of the 'count-down' element of the process, and
the elements at the 'end' of the array would be more likely to be
ignored. But then the elements that stayed the same would be more likely
to be those high-end elements, wouldn't they(?), and they weren't.
But I wrote my own, anyway, in the way that I thought would be simplest
ie extract a random element, and put it in a new array.
sub new_order {
my @ray = @array; # I was using a global for the testing...
my @new_order = ();
push @new_order, (splice @ray, (int rand @ray), 1) while (@ray);
return \@new_order;
}
and a quick test gave this lot...
mine FY
four one three two : 4226 .. four one three two : 4257
four one two three : 4240 .. four one two three : 4081
four three one two : 4187 .. four three one two : 4153
four three two one : 4254 .. four three two one : 4228
four two one three : 4270 .. four two one three : 4157
four two three one : 4167 .. four two three one : 4042
one four three two : 4219 .. one four three two : 4074
one four two three : 4199 .. one four two three : 4211
one three four two : 4199 .. one three four two : 4215
one three two four : 4172 .. one three two four : 4290
one two four three : 4071 .. one two four three : 4204
one two three four : 4210 .. one two three four : 4206
three four one two : 4070 .. three four one two : 4223
three four two one : 4096 .. three four two one : 4129
three one four two : 4183 .. three one four two : 4178
three one two four : 4227 .. three one two four : 4161
three two four one : 4079 .. three two four one : 4143
three two one four : 4109 .. three two one four : 4038
two four one three : 4205 .. two four one three : 4076
two four three one : 4002 .. two four three one : 4215
two one four three : 4168 .. two one four three : 4173
two one three four : 4170 .. two one three four : 4158
two three four one : 4128 .. two three four one : 4211
two three one four : 4149 .. two three one four : 4177
So I guess they both seem to produce a pretty (very?) even spread of
results.
Jasper
Oh, and speed:
Benchmark: running mine, yate, each for at least 3 CPU seconds...
mine: 4 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @
9299.00/s (n=27897)
fisher: 5 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @
7380.33/s (n=22141)
I was going to include your code, Stuart, but it seemed slightly b0rked
($j was out of scope in places, and when I put it in scope, the results
were whacko).
--
split//,'019617511192'.
'17011111610114101114'.
'21011141011840799901'.
'17101174';
foreach(0.. # my
$#_){$_[$_ # signature is too
++]^=$_[$_ # bignature
--]^=$_[$_
]^=$_[++ $_]if!($_%
2)}$g.=$_ ,chr($g)=~
/(\w)/&&($o.=$1and
$g='')foreach@_;
print"$o\n"
------------------------------
Date: Tue, 04 Sep 2001 16:23:06 +0200
From: Heiko Wolf <wolfh@master.sm.go.dlr.de>
Subject: Shell Scripts vs. Perl Scripts
Message-Id: <3B94E3CA.236E2F5B@master.sm.go.dlr.de>
Hello,
I want to execute a bs script from a perl script.
How can I do this? Is there a kind of "run"-command?
My second question is about perl and Browsers:
Is there a way that I can force the Browser to reload the actual site
after executing a perl-script?
I don't know if this is the right newsgroup for these questions, but I'm
very new to Perl and UNIX, perhaps someone may help me.
Best Regards
Heiko Wolf
------------------------------
Date: Tue, 04 Sep 2001 15:49:57 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <slrn9p9rau.rbn.tadmc@tadmc26.august.net>
Heiko Wolf <wolfh@master.sm.go.dlr.de> wrote:
>I want to execute a bs script from a perl script.
^^
Eh? Did you mean "bash" instead?
What is "bs"? (apart from the usual colloquial expansion)
>How can I do this? Is there a kind of "run"-command?
perldoc -f system
perldoc -f qx
perldoc -q external
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 4 Sep 2001 17:57:46 +0200
From: "fruiture" <info@fruiture.de>
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <9n2u4h$480$01$1@news.t-online.com>
"Heiko Wolf" <wolfh@master.sm.go.dlr.de> wrote:
> Hello,
>
> I want to execute a bs script from a perl script.
> How can I do this? Is there a kind of "run"-command?
has been answered
>
> My second question is about perl and Browsers:
> Is there a way that I can force the Browser to reload the actual site
> after executing a perl-script?
>
wow! Which browser executes perl-scripts? Really great!
--
require Time::HiRes;my @m=split(/8/,55.52.56.49.49.55.56.49.49.53);push
@m,map{($_%2)?$_-1:$_+1} map ord($_),split//,'u!`onuids!Qdsm!i`bjds';
unshift @m,43 for(0..@m);for(0..@m){print map chr($_),@m[0..(@m/2-1)];
push @m,shift @m;print "\b"x(@m/2);Time::HiRes::usleep(0246*0xA**3);}
------------------------------
Date: Tue, 04 Sep 2001 14:03:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: weird kind of eof
Message-Id: <fin9ptce1r1omo7ahv73eeqaa9il6jkcg3@4ax.com>
Jonadab the Unsightly One wrote:
>Another posted gave an example for how
>to remove decimal 015 and 012, but you could just as
>well remove 026, or 010 and 013,
It's not decimal 015 and 012, but octal. Those represent 13 and 10
respectively.
As for the op:
s/\^M//g
isn't going to do you any good. You likely want
s/\cM//g
which again is another way to delete "\015" or "\x0D" (CR, chr(13)).
But I think you're seeing a bare LF (chr(10)).
--
Bart.
------------------------------
Date: Tue, 04 Sep 2001 15:48:00 GMT
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: weird kind of eof
Message-Id: <QI6l7.35273$6x5.7708339@afrodite.telenet-ops.be>
Thanks to all, I will try your code and see what works best.
Yes of course I meant EOL, not EOF. Mistake due to several hours of coding,
I guess.
Thanks again
Bart
"Bart Van der Donck" <bart@nijlen.com> schreef in bericht
news:zjSk7.34414$6x5.7423595@afrodite.telenet-ops.be...
> Hello,
>
> My string contains an eof that I cannot detect.
> The purpose is to delete the eof from my string.
>
> I tried about all to delete it:
> chop $a;
> chomp $a;
> $a=~s/\n\gi;
> $a=~s/\\n\gi;
> $a=~s/\^M//gi;
> and some others that I found in the docs.
>
> In notepad the string appears as a little square. On a unix prompt it has
> the same effect as pressing the "Return"-key.
>
> The question is:
> Is there a line that erases all kinds of eofs (DOS, Unix) from my string ?
>
> Many thanks
> Bart
>
>
------------------------------
Date: Fri, 31 Aug 2001 15:53:20 +0200
From: Jean-Luc Fontaine <jfontain@winealley.com>
Subject: Re: Which language better
Message-Id: <3B8F96D0.1050309@winealley.com>
Cameron Laird wrote:
> In article <3B8F8C33.2D8D88B4@mailcity.com>,
> Prakash Mishra <pmishra@mailcity.com> wrote:
>
>>I am working on developing a tool which would be used for functionality testing
>>of DSL devices. Mostly it will be used for testing the SNMP agent part of the
>>device. Now here the speed of the application, memory usage etc does matter.
>>Platform is Solaris. So I wanted information in these regards.
>>
> .
> .
> .
> Ah!
>
> I strongly prefer Scotty, the Tcl-based SNMP-savvy shell.
> It's far more mature and capable than anything Perl offers.
Indeed. And if you decide to use scotty, you can couple it with moodss
to make graphs, dashboards, ... from your running agent.
> However, if you're far more comfortable with Perl than Tcl,
> and don't need all of Scotty's power, than Perl might be
> better for you.
I hate Perl (off subject but it makes me feel better :-).
Jean-Luc
------------------------------
Date: Tue, 04 Sep 2001 17:20:00 GMT
From: gauthier@circum.com (Benoit Gauthier)
Subject: Why doesn't this regex work?
Message-Id: <3b950ceb.22881610@news.videotron.ca>
(2001.09.04, 13:18)
In my view, this code should truncate the variable to 20 characters.
It does not work. Why?
$data = "1234567 101234567 201234567 30";
print "$data\n";
$data =~ s/(.{0-20})/$1/;
print "$data\n";
$data =~ /(.{0-20})/;
$data = $1;
print "$data\n";
Benoit Gauthier
gauthier@circum.com
------------------------------
Date: Tue, 04 Sep 2001 18:30:46 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: Why doesn't this regex work?
Message-Id: <3B950FC6.16D6523F@guideguide.com>
Benoit Gauthier wrote:
>
> (2001.09.04, 13:18)
>
> In my view, this code should truncate the variable to 20 characters.
> It does not work. Why?
>
> $data = "1234567 101234567 201234567 30";
> print "$data\n";
>
> $data =~ s/(.{0-20})/$1/;
> print "$data\n";
for both of these, replace {0-20} with {0,20}.
This s/// won't do anything, because it's replacing the first 20
characters with the same 20 characters, and not affecting the rest
(after you change the - to a ,).
>
> $data =~ /(.{0-20})/;
> $data = $1;
> print "$data\n";
This does work when you change the regex.
Although for just grabbing the first 20 characters, I'd be tempted to
use:
substr($string, 0, 20)
Jasper
--
split//,'019617511192'.
'17011111610114101114'.
'21011141011840799901'.
'17101174';
foreach(0.. # my
$#_){$_[$_ # signature is too
++]^=$_[$_ # bignature
--]^=$_[$_
]^=$_[++ $_]if!($_%
2)}$g.=$_ ,chr($g)=~
/(\w)/&&($o.=$1and
$g='')foreach@_;
print"$o\n"
------------------------------
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.
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 1691
***************************************