[30871] in Perl-Users-Digest
Perl-Users Digest, Issue: 2116 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 12 03:09:44 2009
Date: Mon, 12 Jan 2009 00:09:08 -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 Mon, 12 Jan 2009 Volume: 11 Number: 2116
Today's topics:
Re: Chart::Gnuplot problem (Vicky Conlan)
Re: Circular lists <jurgenex@hotmail.com>
Re: Circular lists <jurgenex@hotmail.com>
Re: Circular lists xhoster@gmail.com
Re: Circular lists xhoster@gmail.com
Re: Circular lists xhoster@gmail.com
How can I access file on machine by address like \\a_ma <WaterLin1999@gmail.com>
Re: Is someone trying to delete this group? <cwilbur@chromatico.net>
new CPAN modules on Mon Jan 12 2009 (Randal Schwartz)
Re: opening a file <hjp-usenet2@hjp.at>
Re: opening a file <tadmc@seesig.invalid>
Re: opening a file <george@example.invalid>
Re: opening a file <george@example.invalid>
Re: opening a file <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 12 Jan 2009 00:01:32 +0000 (UTC)
From: comps@riffraff.plig.net (Vicky Conlan)
Subject: Re: Chart::Gnuplot problem
Message-Id: <gke18s$1m13$1@magenta.plig.net>
> You can tell Chart::Gnuplot
> which one to use by the option "gnuplot", e.g.
>
> $chart = Chart::Gnuplot->new(
> gnuplot => "/usr/bin/gnuplot-4.2.3",
> ......
> );
Changing to version 4.2.3 does indeed seem to have fixed the problem!
Many thanks to those who helped.
--
------------------------------
Date: Sun, 11 Jan 2009 16:30:27 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Circular lists
Message-Id: <ij3lm45do1te4p72jhc537drh47c4roqvn@4ax.com>
xhoster@gmail.com wrote:
>Jürgen Exner <jurgenex@hotmail.com> wrote:
>> gamo <gamo@telecable.es> wrote:
>> >
>> >If a,b,c is a list
>> >b,c,a is the same list rotated b,c,a,b,c,a (note the a,b,c)
>> >c,a,b is the same too, because c,a,b,c,a,b (note the a,b,c)
>> >
>> >a,c,b is another list because a,c,b,a,c,b is new
>> >
>> >I expect this clarifies the problem.
>>
>> Are you confirming Red's understanding of the problem or are you
>> correcting his understanding? To me both versions, his and yours, seem
>> to be the same.
>>
>> If they are, then generating all your "circular lists" is trivial, as is
>> computing their number.
>>
>> Obviously there are exactly as many circular lists as there are elements
>> in the original list, because each element can become the first element
>> in a result list.
>
>
>ababab only has two linear representations,not 6.
Good catch, you are right.
>I think your claim is true if and only if the counts of the occurrences of
>distinct letters in the input @set have a lcf of 1.
What's an lcf? http://en.wikipedia.org/wiki/LCF has numerous
suggestions, but none that seems to fit in this context.
jue
------------------------------
Date: Sun, 11 Jan 2009 16:36:29 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Circular lists
Message-Id: <tq3lm4ldn3lfqcjg3cl4t7lu7vhehl99r1@4ax.com>
xhoster@gmail.com wrote:
>gamo <gamo@telecable.es> wrote:
>> > >
>> > > I have a set of @set =3D qw(a a b b b c c c c);
>> > >
>> > > In a loop...
>> > >
>> > > @list =3D shuffle(@set);
>> >=20
>> > Is this the shuffle from List::Util? If so, why use a random method
>> > as part of determining a non-random result? If you want to inspect
>> > every permutation, don't do it randomly.
>>
>> I don't want to inspect every permutation because the number of
>> permutations is n! =3D n*(n-1)*(n-2)...*1 and a problem of 20! is
>> intractable.
>
>There only that many permutations if your "set" has only unique letters,
>which in your example it does not.
Well, I wonder what George is actually talking about. He is saying set,
but as you pointed out he is using a multi-set (or maybe a list?), and
then later he is talking about lists.
>Anyway, may gut feeling is that to get
>an accurate count based on stochastic sampling, your will need to be about
>as large as the underlying domain, anyway. But I could be wrong.
Unless George manages to explain his problem precisely in terms that
everyone can understand and doesn't keep changing his story I have
little hope that we can even agree about the problem to be solved, let
alone agree on a solution.
A formal spec would be nice, but I guess that is too much to ask.
jue
------------------------------
Date: 12 Jan 2009 01:34:20 GMT
From: xhoster@gmail.com
Subject: Re: Circular lists
Message-Id: <20090111203636.277$KT@newsreader.com>
> On Fri, 9 Jan 2009, gamo wrote:
>
> for $j (1..$precounter){
> if ($s eq $p[$j]){
> $ok=0;
> last;
> }
> };
This would be better written as a hash look up. To do so, the easiest way
is move it above the hash population, and do away with @p altogether,
giving:
for (1..10_000_000){
my @set = shuffle(@a);
my $s = join '',@set;
my $two = $s . $s;
next if ($two =~ /gg/);
unless (exists $hash{$s}){
$exito++;
print "$0 $exito\n";
}
for my $i (0..9){
my $r = substr $two,$i,10;
$hash{$r}++;
}
}
This should be a lot faster. (In addition to other things mentioned
previously, the hard-coding of 9 and 10 in the above is not a good idea)
If RAM becomes a premium, you could put only one canonical sequence
in the hash, rather than every rotation:
for (1..10_000_000){
my @set = shuffle(@a);
my $s = join '',@set;
my $two = $s . $s;
next if ($two =~ /gg/);
my ($canon) = sort map {substr $two,$_,length $s} 0..length($s) -1;
unless (exists $hash{$canon}){
$hash{$canon}++;
$exito++;
print "$0 $exito\n";
}
}
print "El número de permutaciones circulares es $exito\n";
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 12 Jan 2009 01:37:59 GMT
From: xhoster@gmail.com
Subject: Re: Circular lists
Message-Id: <20090111204014.862$CQ@newsreader.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> xhoster@gmail.com wrote:
> >I think your claim is true if and only if the counts of the occurrences
> >of distinct letters in the input @set have a lcf of 1.
>
> What's an lcf? http://en.wikipedia.org/wiki/LCF has numerous
> suggestions, but none that seems to fit in this context.
Oops. I meant gcf, greatest common factor. (lcf, least common factor, is
pretty trivial, which is probably why there is no entry for it.)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 12 Jan 2009 02:02:58 GMT
From: xhoster@gmail.com
Subject: Re: Circular lists
Message-Id: <20090111210513.735$g0@newsreader.com>
Previously, I wrote about getting only distinct permutations:
> There may already be a module for that on CPAN, but if so finding it
> seems as hard as making one. So I whipped up something easy to implement
> (but not to use)
>
> To make a good module out of it, recursion should be removed and
> reimplemented with explicit state and as an iterator rather than a
> callback.
I've done the above mentioned conversion:
my $iter=Distinct::Permute->new(qw/a a a a a r r g g n/);
while (my @x=$iter->next) {
print "@x\n";
};
package Distinct::Permute;
sub new {
"Distinct::Permute" eq shift @_ or die "Not subclassable";
my %h;
foreach (@_) {
$h{$_}++;
};
my @alpha=keys %h;
my @counts=values %h;
my @first;
push @first, (($_) x $counts[$_]) foreach 0..$#alpha;
return bless {alpha => \@alpha, counts=> \@counts, now => \@first};
};
sub next {
my $self=shift;
return if exists $self->{done};
my @return = map $self->{alpha}[$_], @{$self->{now}};
## climb back off the length until we have backed off far enough that
## the next iteration doesn't need to change anything to the left of us.
my $climb=$#{$self->{now}};
my @left = (0)x @{$self->{alpha}};
my $max_left = -1; # highest digit with any left to choose
while ($climb >=0) {
last if $self->{now}[$climb] < $max_left;
$max_left = $self->{now}[$climb] if $self->{now}[$climb] > $max_left;
$left[ $self->{now}[$climb] ] ++;
$climb--;
};
if ($climb<0) {
$self->{done}=1;
return @return;
};
# roll over the digit that needs it:
$left[ $self->{now}[$climb] ]++;
do {$self->{now}[$climb]++} until $left[ $self->{now}[$climb] ];
$left[ $self->{now}[$climb] ]--;
# fill out rest
foreach my $digit (0..$#left) {
foreach (1..$left[$digit]) {
$self->{now}[++$climb]=$digit;
};
};
return @return
};
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Sun, 11 Jan 2009 22:44:24 -0800 (PST)
From: Water Lin <WaterLin1999@gmail.com>
Subject: How can I access file on machine by address like \\a_machine\pub\list
Message-Id: <421b46ae-e26b-4d80-a85a-260e55a1d762@f40g2000pri.googlegroups.com>
I need to access file under Windows XP. The path on the network is
something like \\a_machine\pub\list
I don't know what kind of this protocol is. And I don't know how I can
access this folder by Perl.
By the way, I am using Strawberry Perl under Windows XP.
Anyone has experience about this?
------------------------------
Date: Sun, 11 Jan 2009 18:23:12 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Is someone trying to delete this group?
Message-Id: <861vv94ecf.fsf@mithril.chromatico.net>
>>>>> "PJH" == Peter J Holzer <hjp-usenet2@hjp.at> writes:
PJH> comp.lang.perl doesn't exist any more, so you can't talk about
PJH> perl there.
Except on poorly-configured news servers, of which there are a great
many.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 12 Jan 2009 05:42:23 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Jan 12 2009
Message-Id: <KDCFun.K13@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AI-Genetic-Pro-0.26
http://search.cpan.org/~strzelec/AI-Genetic-Pro-0.26/
Efficient genetic algorithms for professional purpose.
----
AI-Genetic-Pro-0.27
http://search.cpan.org/~strzelec/AI-Genetic-Pro-0.27/
Efficient genetic algorithms for professional purpose.
----
AI-Genetic-Pro-0.28
http://search.cpan.org/~strzelec/AI-Genetic-Pro-0.28/
Efficient genetic algorithms for professional purpose.
----
Algorithm-FloodControl-1.98
http://search.cpan.org/~gugu/Algorithm-FloodControl-1.98/
Limit event processing to count/time ratio.
----
Apache2-ASP-2.11
http://search.cpan.org/~johnd/Apache2-ASP-2.11/
ASP for Perl, reloaded.
----
CPAN-1.93_02
http://search.cpan.org/~andk/CPAN-1.93_02/
query, download and build perl modules from CPAN sites
----
Catalyst-View-JavaScript-0.99
http://search.cpan.org/~perler/Catalyst-View-JavaScript-0.99/
Cache and/or compress JavaScript output
----
CatalystX-ListFramework-Builder-0.39
http://search.cpan.org/~oliver/CatalystX-ListFramework-Builder-0.39/
Instant AJAX web front-end for DBIx::Class, using Catalyst
----
Config-IniHash-3.00.02
http://search.cpan.org/~jenda/Config-IniHash-3.00.02/
Perl extension for reading and writing INI files
----
Github-Import-0.01
http://search.cpan.org/~nuffin/Github-Import-0.01/
Import your project into <http://github.com>
----
Google-Code-Upload-0.01
http://search.cpan.org/~fayland/Google-Code-Upload-0.01/
uploading files to a Google Code project.
----
Gtk2-Ex-DateSpinner-2
http://search.cpan.org/~kryde/Gtk2-Ex-DateSpinner-2/
year/month/day date entry using SpinButtons
----
HTTP-Server-Simple-0.38
http://search.cpan.org/~jesse/HTTP-Server-Simple-0.38/
Lightweight HTTP server
----
Hyper-v0.05
http://search.cpan.org/~acid/Hyper-v0.05/
The global Hyper Workflow Interface
----
IO-Lambda-1.02
http://search.cpan.org/~karasik/IO-Lambda-1.02/
non-blocking I/O as lambda calculus
----
MooseX-POE-0.1
http://search.cpan.org/~perigrin/MooseX-POE-0.1/
The Illicit Love Child of Moose and POE
----
MouseX-Log-Dispatch-Config-0.03
http://search.cpan.org/~masaki/MouseX-Log-Dispatch-Config-0.03/
A Mouse role for logging
----
Net-MRIM-1.11
http://search.cpan.org/~aau/Net-MRIM-1.11/
Perl implementation of mail.ru agent protocol
----
Net-OpenSSH-0.16
http://search.cpan.org/~salva/Net-OpenSSH-0.16/
Perl SSH client package implemented on top of OpenSSH
----
Net-Twitter-2.00_04
http://search.cpan.org/~cthom/Net-Twitter-2.00_04/
Perl interface to twitter.com
----
PHP-Serialization-0.30
http://search.cpan.org/~bobtfish/PHP-Serialization-0.30/
simple flexible means of converting the output of PHP's serialize() into the equivalent Perl memory structure, and vice versa.
----
POE-Component-Client-FTP-0.22
http://search.cpan.org/~bingos/POE-Component-Client-FTP-0.22/
Implements an FTP client POE Component
----
Path-Router-0.06
http://search.cpan.org/~hdp/Path-Router-0.06/
A tool for routing paths
----
Perl-Critic-Pulp-13
http://search.cpan.org/~kryde/Perl-Critic-Pulp-13/
some add-on perlcritic policies
----
SMS-Send-TW-emome-0.03
http://search.cpan.org/~snowfly/SMS-Send-TW-emome-0.03/
SMS::Send driver for www.emome.net
----
SVN-Hooks-0.13.11
http://search.cpan.org/~gnustavo/SVN-Hooks-0.13.11/
A framework for implementing Subversion hooks.
----
Scope-Upper-0.04
http://search.cpan.org/~vpit/Scope-Upper-0.04/
Act on upper scopes.
----
Speechd-0.50
http://search.cpan.org/~jkamphaus/Speechd-0.50/
Perl Module wrapper for speech-dispatcher.
----
Storable-AMF-0.41
http://search.cpan.org/~grian/Storable-AMF-0.41/
Perl extension for serialize/deserialize AMF0/AMF3 data
----
Syntax-Highlight-Perl6-0.031
http://search.cpan.org/~azawawi/Syntax-Highlight-Perl6-0.031/
Perl 6 Syntax Highlighter
----
Syntax-Highlight-Perl6-0.032
http://search.cpan.org/~azawawi/Syntax-Highlight-Perl6-0.032/
Perl 6 Syntax Highlighter
----
Test-DBUnit-0.19
http://search.cpan.org/~adrianwit/Test-DBUnit-0.19/
Database testing framework.
----
WWW-Search-Ebay-Europe-2.008
http://search.cpan.org/~mthurn/WWW-Search-Ebay-Europe-2.008/
search for auctions at European eBay sites
----
WWW-Search-Yahoo-2.414
http://search.cpan.org/~mthurn/WWW-Search-Yahoo-2.414/
backend for searching www.yahoo.com
----
WWW-Tube8-0.0.3
http://search.cpan.org/~bayashi/WWW-Tube8-0.0.3/
Get video informations from tube8.com
----
Web-Scraper-0.25
http://search.cpan.org/~miyagawa/Web-Scraper-0.25/
Web Scraping Toolkit inspired by Scrapi
----
YAML-LibYAML-0.30
http://search.cpan.org/~nuffin/YAML-LibYAML-0.30/
----
minismokebox-0.01_03
http://search.cpan.org/~bingos/minismokebox-0.01_03/
a small lightweight SmokeBox
----
xcruciate-003
http://search.cpan.org/~melonman/xcruciate-003/
----
xcruciate-unitconfig-003
http://search.cpan.org/~melonman/xcruciate-unitconfig-003/
----
xcruciate-utils-002
http://search.cpan.org/~melonman/xcruciate-utils-002/
----
xcruciate-utils-003
http://search.cpan.org/~melonman/xcruciate-utils-003/
----
xcruciate-xcruciateconfig-003
http://search.cpan.org/~melonman/xcruciate-xcruciateconfig-003/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Mon, 12 Jan 2009 00:04:41 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: opening a file
Message-Id: <slrngmkuo9.fe6.hjp-usenet2@hrunkner.hjp.at>
On 2009-01-11 21:20, George <george@example.invalid> wrote:
> On Sat, 10 Jan 2009 07:27:01 -0800, Jürgen Exner wrote:
>
>> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>>On 2009-01-10 03:11, George <george@example.invalid> wrote:
>>>> On Fri, 09 Jan 2009 18:24:38 -0800, Jürgen Exner wrote:
>>>>> George <george@example.invalid> wrote:
>>>>>> open(50, '<ehp3.txt>');
>>>>>> DO:
>>>>>> { my $line = readline(*50);
>>>>>> if(eof != 0) { exit }
>>>>>> print $line; # no 'write' here
>>>>>> redo DO } # no 'end' possible
>>>>>> close(50)
>>>>>
>>>>> Ouch! This hurts!
>>>
>>>I'm sure Mirco meant that as a joke.
>>
>> Unfortunately is seems like George didn't get that joke :-(
>
> What joke? Mirco made the perl syntax match my previous notions,
This is the joke. He wrote completely unidiomatic (and quite horrible)
Perl which looks almost like Fortran, alluding to the well-known joke
that "real programmers can write Fortran programs in any language"[1]
(which you cited yourself earlier in the thread).
> and [...] it works:
That makes it even funnier.
hp
[1] Real Programmers Don't Use Pascal. Ed Post, Tektronix, Wilsonville
OR, USA. Letter to the editor of Datamation, volume 29 number 7,
July 1983.
http://www.pbm.com/~lindahl/real.programmers.html
------------------------------
Date: Sun, 11 Jan 2009 17:18:29 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: opening a file
Message-Id: <slrngmkvi5.lvg.tadmc@tadmc30.sbcglobal.net>
George <george@example.invalid> wrote:
> #The manuals don't really say it but files have their own data type.
Files do NOT have their own data type.
Filehandles have their own data type though.
> #This line creates a variable called file or exits saying that it can't
This line creates a filehandle called FILE.
Case matters.
> open( FILE, "eph4.txt") || die "Could not open ehp3.txt $!";
^^
^^ oops yet again...
But in modern perls, using a lexical filehandle, along with the 3-arg
form of open() is much much better, so you might as well learn the
best way rather than the anachronistic way:
open( my $FILE, '<', 'eph4.txt') || die "Could not open 'eph4.txt' $!";
or, without superfluous punctuation:
open my $FILE, '<', 'eph4.txt' or die "Could not open 'eph4.txt' $!";
> #read out one line at a time until the file ends
> while( <FILE> ){
> print $_; #If you don't specify a file it goes to STDOUT (STandard
> OUTpu
> t)
> #The $_ variable is created by the while statement
The $_ variable is NOT created by the while statement.
The $_ variable is populated by the while statement though.
> close(FILE); #This might not really be needed
But it is always a good idea, else you are likely to forget
one of those rare times where it really is needed.
A tale of woe where _I_ forgot once, and worked all day for no pay:
http://groups.google.com/groups/search?as_umsgid=slrnclb8ta.qpk.tadmc%40magna.augustmail.com
> open my $handle, '<', $filename
> or die "unable to open '$filename' because $!";
Much better! :-)
> Page 21 of the camel book is the reference a person needs for this.
There are 3 "Page 21 of the camel book", since there are 3 editions
of the book...
Books are only supplemental references, you consult them if the
primary references for Perl does not satisfy.
Simply reading the std docs for the functions you are using is
often enough.
> The
> '<' means explicitly to read from an existing file.
perldoc -f open
If MODE is '<' or nothing, the file is opened for input.
> Does someone have a reference for the three-argument form for open?
Everyone who has perl has a reference for the three-argument form for open:
perldoc -f open
If three or more arguments are specified then ...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 11 Jan 2009 19:40:17 -0700
From: George <george@example.invalid>
Subject: Re: opening a file
Message-Id: <1mxqacirp0r7w.b5vi5tlynims$.dlg@40tude.net>
On Sun, 11 Jan 2009 17:18:29 -0600, Tad J McClellan wrote:
> George <george@example.invalid> wrote:
>
>
>> #The manuals don't really say it but files have their own data type.
>
>
> Files do NOT have their own data type.
>
> Filehandles have their own data type though.
ok
>
>
>> #This line creates a variable called file or exits saying that it can't
>
>
> This line creates a filehandle called FILE.
>
> Case matters.
ok
>
>
>> open( FILE, "eph4.txt") || die "Could not open ehp3.txt $!";
> ^^
> ^^ oops yet again...
>
> But in modern perls, using a lexical filehandle, along with the 3-arg
> form of open() is much much better, so you might as well learn the
> best way rather than the anachronistic way:
>
> open( my $FILE, '<', 'eph4.txt') || die "Could not open 'eph4.txt' $!";
>
> or, without superfluous punctuation:
>
> open my $FILE, '<', 'eph4.txt' or die "Could not open 'eph4.txt' $!";
But I think you have to go Peter's notion that you want your script to tell
you *exactly* what file you asked for:
my $filename = 'eph3.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
How does $filename: $! become eph3.txt, when the OS can't find it?
>
>
>> #read out one line at a time until the file ends
>> while( <FILE> ){
>> print $_; #If you don't specify a file it goes to STDOUT (STandard
>> OUTpu
>> t)
>> #The $_ variable is created by the while statement
>
>
> The $_ variable is NOT created by the while statement.
>
> The $_ variable is populated by the while statement though.
ok
>
>
>> close(FILE); #This might not really be needed
>
>
> But it is always a good idea, else you are likely to forget
> one of those rare times where it really is needed.
>
> A tale of woe where _I_ forgot once, and worked all day for no pay:
>
> http://groups.google.com/groups/search?as_umsgid=slrnclb8ta.qpk.tadmc%40magna.augustmail.com
>
That's good reading. I call that "biting my tail" programming. If you
ever have an ecumenical discussion with a fortran guy, you could explain
the filehandles as unit numbers. For fortran, they are nonnegative
integers with 5 as stdin and 6 as stdout. We recommend explicit closes as
well.
>
>
>> open my $handle, '<', $filename
>> or die "unable to open '$filename' because $!";
>
>
> Much better! :-)
I'd like to say "shucks," but I don't know what $! does.
>
>
>> Page 21 of the camel book is the reference a person needs for this.
>
>
> There are 3 "Page 21 of the camel book", since there are 3 editions
> of the book...
Mine's current.
>
> Books are only supplemental references, you consult them if the
> primary references for Perl does not satisfy.
>
> Simply reading the std docs for the functions you are using is
> often enough.
>
>
>> The
>> '<' means explicitly to read from an existing file.
>
>
> perldoc -f open
>
> If MODE is '<' or nothing, the file is opened for input.
>
>
>> Does someone have a reference for the three-argument form for open?
>
>
> Everyone who has perl has a reference for the three-argument form for open:
>
> perldoc -f open
>
> If three or more arguments are specified then ...
I pulled some of this material out:
You may also, in the Bourne shell tradition, specify an EXPR
beginning with '>&', in which case the rest of the string is
interpreted as the name of a filehandle (or file descriptor, if
numeric) to be duped (as dup(2)) and opened. You may use "&"
after ">", ">>", "<", "+>", "+>>", and "+<". The mode you
specify should match the mode of the original filehandle.
(Duping a filehandle does not take into account any existing
contents of IO buffers.) If you use the 3-arg form then you can
pass either a number, the name of a filehandle or the normal
"reference to a glob".
open FILEHANDLE,MODE,EXPR
open FILEHANDLE,MODE,REFERENCE
As a special case the 3-arg form with a read/write mode and the
third argument being "undef":
open(TMP, "+>", undef) or die ...
opens a filehandle to an anonymous temporary file. Also using
"+<" works for symmetry, but you really should consider writing
something to the temporary file first. You will need to seek()
to do the reading.
How does perl.exe know whether the third argument is an expression or a
reference?
--
George
The men and women of Afghanistan are building a nation that is free, and
proud, and fighting terror - and America is honored to be their friend.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
------------------------------
Date: Sun, 11 Jan 2009 20:17:53 -0700
From: George <george@example.invalid>
Subject: Re: opening a file
Message-Id: <gnn04h8kk7bk.n44k9h8z4etu$.dlg@40tude.net>
On Mon, 12 Jan 2009 00:04:41 +0100, Peter J. Holzer wrote:
> On 2009-01-11 21:20, George <george@example.invalid> wrote:
>> What joke? Mirco made the perl syntax match my previous notions,
>
> This is the joke. He wrote completely unidiomatic (and quite horrible)
> Perl which looks almost like Fortran, alluding to the well-known joke
> that "real programmers can write Fortran programs in any language"[1]
> (which you cited yourself earlier in the thread).
Real programmers, like clf's Catherine Zeta Lay, express what I precisely
meant in german:
Wir meinen damit daß das abwertend ist, fortran sonstwo zu üben.
This translates as:
We mean that the pejorative is fortran elsewhere to practice.
>
>> and [...] it works:
>
> That makes it even funnier.
>
> hp
>
> [1] Real Programmers Don't Use Pascal. Ed Post, Tektronix, Wilsonville
> OR, USA. Letter to the editor of Datamation, volume 29 number 7,
> July 1983.
> http://www.pbm.com/~lindahl/real.programmers.html
I know Greg! I was programming in 1983 for the Man who taught me
everything: Leroy Wentz.
Greg is a subscriber to the "big tent" inclusion ethos of
comp.lang.fortran: the topic always seems to return when we are civil.
--
George
The course of this conflict is not known, yet its outcome is certain.
Freedom and fear, justice and cruelty, have always been at war, and we know
that God is not neutral between them.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
------------------------------
Date: Sun, 11 Jan 2009 22:38:58 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: opening a file
Message-Id: <slrngmlib2.p4j.tadmc@tadmc30.sbcglobal.net>
George <george@example.invalid> wrote:
> On Sun, 11 Jan 2009 17:18:29 -0600, Tad J McClellan wrote:
>
>> George <george@example.invalid> wrote:
> But I think you have to go Peter's notion that you want your script to tell
> you *exactly* what file you asked for:
Excellent idea.
> my $filename = 'eph3.txt';
> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>
> How does $filename: $! become eph3.txt, when the OS can't find it?
I do not understand your question.
If the file cannout be found, you'll get output something like:
cannot open eph3.txt: File not found
>>> open my $handle, '<', $filename
>>> or die "unable to open '$filename' because $!";
>>
>>
>> Much better! :-)
>
> I'd like to say "shucks," but I don't know what $! does.
It is a Perl variable.
All of Perl's variables are documented in:
perldoc perlvar
I don't remember what fortran called it, but Perl's $! is errno in C.
If used as a string rather than a number, then perl will look up
that error number for you, and its value will be "permission denied"
or "file not found" or some such.
> How does perl.exe know whether the third argument is an expression or a
> reference?
perldoc -f ref
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
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 V11 Issue 2116
***************************************