[25405] in Perl-Users-Digest
Perl-Users Digest, Issue: 7650 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 14 18:05:46 2005
Date: Fri, 14 Jan 2005 15:05:16 -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 Fri, 14 Jan 2005 Volume: 10 Number: 7650
Today's topics:
Re: [perl-python] 20050113 looking up syntax <ialbert@mailblocks.com>
Re: Advice on starting form based application dbmeyers23@yahoo.com
Re: Basic Question: Local Forms <nobull@mail.com>
Re: convention regarding lexical filehandles <abigail@abigail.nl>
Re: convention regarding lexical filehandles <abigail@abigail.nl>
Re: convention regarding lexical filehandles <spamtrap@dot-app.org>
Re: convention regarding lexical filehandles <abigail@abigail.nl>
Re: disk space script <spamtrap@dot-app.org>
Re: Except script error <bik.mido@tiscalinet.it>
Re: Except script error <noelt.dolan@virgin.net>
Re: Except script error <geen@mail.invalid>
Re: How to convert MS doc to plain text using Perl on u <tintin@invalid.invalid>
Re: how upload files with Perl using MySQL database <nospam@nospam.tv>
Re: how upload files with Perl using MySQL database <spamtrap@dot-app.org>
Re: how upload files with Perl using MySQL database <kkeller-usenet@wombat.san-francisco.ca.us>
Re: how upload files with Perl using MySQL database <toreau@gmail.com>
Re: Log File parser <jc8glp1hu@gmail.com>
Re: Log File parser (Anno Siegel)
Re: Loop through a text file line by line toomanyjoes@mail.utexas.edu
Re: Loop through a text file line by line toomanyjoes@mail.utexas.edu
Re: Loop through a text file line by line <spamtrap@dot-app.org>
Re: Loop through a text file line by line <spamtrap@dot-app.org>
Math::NumberCruncher-5.00 bug WCR.III@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 14 Jan 2005 14:17:18 -0500
From: Istvan Albert <ialbert@mailblocks.com>
Subject: Re: [perl-python] 20050113 looking up syntax
Message-Id: <3qadneWfvaojh3XcRVn-vg@giganews.com>
Jürgen Exner wrote:
> Why don't you just stop posting this nonsense?
He will, fairly soon. I'm suspecting that the original
intent behind these posts was to stir up a perl vs python
flamewar. That is unlikely to materialize since the
poster does not seem to understand neither of these
languages.
I.
------------------------------
Date: 14 Jan 2005 14:42:15 -0800
From: dbmeyers23@yahoo.com
Subject: Re: Advice on starting form based application
Message-Id: <1105742535.122055.155330@f14g2000cwb.googlegroups.com>
Thanks Gunnar, this seems to work well. One last question if you don't
mind. Below is a snippet of the code. This prints out the values
wonderfully to the browser. I'd also like to write the contents to a
file, then mail the contents out. I can get the "Client Name:" to show
up in the email, but the variable is not showing up. I tried many
variations, with no luck...does anyone have any clues on how to do
this?
print $query->header();
my @labels = (
[ clientname => 'Client Name' ],
[ ordernumber => 'Order Number' ],
)
open (INT_EMAIL, ">/usr/local/apache2/ads/xxx.txt") || die "Can't open
email\n";
print "Success! <br>";
print "You entered the following information:<br>";
print "<br>";
for (@labels) {
if ( $query->param( $$_[0] ) ) {
print "$$_[1]: ", $query->param( $$_[0] ), "<br>";
printf INT_EMAIL ("$$_[1]: ", $query->param( $$_[0] ),
"\r\n");
}
}
close (INT_EMAIL);
$Subject="New Ad request";
`cat /usr/local/apache2/ads/xxx.txt | /bin/mail -u "ads" -s "$Subject"
ads\@mail.com`;
------------------------------
Date: Fri, 14 Jan 2005 18:56:03 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Basic Question: Local Forms
Message-Id: <cs94b1$21e$1@sun3.bham.ac.uk>
jeannegoodman@yahoo.com rudely vomits TOFU in my face:
[ Please don't do that. Trim the quoted material and place your
responses after the bits you are replying to ]
> Well, perhaps I'm in the wrong place. I was looking for some kind of
> CGI script that would transfer the data to an ascii file.
>
> I have next to no control over the the software and no ability to get a
> webserver.
You are not just in the wrong place, you are in the wrong reality :-).
CGI scripts run on webservers. (Theoretically the CGI API could be used
in other ways but in practice it isn't much. I believe there's even at
least one web browser that can run CGI scripts locally. Kinda pointless
if you ask me since this is just the same as having a local webserver).
If you have no control over the software you are limited to using
programs that are already there. What options you have will therefore
depend on what's already there. It's relatively unlikely that Perl's
already there.
> I was imagining I could create a simple HTML form where the information
> would post to an ascii file. Do I belong in a Java Group?
You would probably do better in a JavaScript group (the JavaScript
language is distinct from the Java language).
However if, as you say, you have next to no control over the browser
that will be used to display the form you are unlikely to be able to get
that JavaScript to access the filesystem.
You could install some sort of trusted Java applet - but this is
definitely way out of my field of expertease. Any anyhow you said you
can't install stuff.
------------------------------
Date: 14 Jan 2005 19:49:37 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: convention regarding lexical filehandles
Message-Id: <slrncug8ig.qo.abigail@alexandra.abigail.nl>
Sherm Pendley (spamtrap@dot-app.org) wrote on MMMMCLIV September MCMXCIII
in <URL:news:ELudnWxHf9V4rHrcRVn-pg@adelphia.com>:
{} Abigail wrote:
{}
{} > Well, so what? The user loses his file. Big deal. Had he typed
{} >
{} > $ cat >file.txt
{} >
{} > he would have lost his file too.
{}
{} Yes, but that's due to a mistake on the user's part, not cat's. Had the user
{} correctly typed
{}
{} $ cat ">file.txt"
{}
{} instead, "cat" would have behaved correctly. In the case of a Perl script
{} that uses "open FILE, $filename", there would be *no* correct way for the
{} user to run the script. The file gets overwritten even if the user
{} correctly quotes it when he runs the script.
But if the user had typed
perl-program "./>file.txt"
nothing would have happened either.
I remain with my opinion that if you put a '>' in your file name,
you're responsible it doesn't get clobbered.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: 14 Jan 2005 19:56:52 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: convention regarding lexical filehandles
Message-Id: <slrncug903.qo.abigail@alexandra.abigail.nl>
Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMMCLIV September
MCMXCIII in <URL:news:ekafu0d40sq6ddmjb5s8ml7mnh9aap1s2h@4ax.com>:
:} On 13 Jan 2005 22:42:51 GMT, Abigail <abigail@abigail.nl> wrote:
:}
:} >I find the two arg form of 'open' useful. And no, I don't create file
:} >names that start with '|', '<' or '>', nor filenames that end with a
:} >'|'. Nor do I include leading or trailing spaces in my filenames.
:}
:} Please note that I'm not one of those '"Perl" eq "CGI"' kinda guys: to
:} be fair I've hardly done any CGI et similia at all, but what if a CGI
:} script (is not run in taint mode and) accepts a parameter to be
:} interpreted as a filename to be opened and someone passes
:}
:} %7Cecho%20'%3CHTML%3E%0A%3CHEAD%3E%0A%3CTITLE%3EYou%20have%20been%20hacked!%
:} FTITLE%3E%0A%3C%2FHEAD%3E%0A%3CBODY%3E%3CH1%3EYou%20have%20been%20hacked!%3C
:} 1%3E%3C%2FBODY%3E%0A%3C%2FHTML%3E'%20%3Eindex.html%0A
:}
:} (beware of line wraps)
:}
:} to it?
Are you saying that if you use three arg open, and blindly accept
filenames from third parties to open, you're safe?
I don't buy this argument. Blindly accepting filenames to open which
are handed to you over CGI is a dumb idea to start with. You will have
to do more than just disabling magic open.
But if you have fixed all other things, you probably still don't want
to use magic open. (But people were able to write safe programs before
we had 3-arg open). However, that doesn't mean that you should always
shun the use of magic open just because you've found a situation were
you don't want to use it.
Abigail
--
#!/opt/perl/bin/perl -- # No trailing newline after the last line!
BEGIN{$|=$SIG{__WARN__}=sub{$_=$_[0];y-_- -;print/(.)"$/;seek _,-open(_
,"+<$0"),2;truncate _,tell _;close _;exec$0}}//rekcaH_lreP_rehtona_tsuJ
------------------------------
Date: Fri, 14 Jan 2005 14:59:06 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: convention regarding lexical filehandles
Message-Id: <Fo2dnd_hJogRuXXcRVn-jA@adelphia.com>
Abigail wrote:
> I remain with my opinion that if you put a '>' in your file name,
> you're responsible it doesn't get clobbered.
The fact is that '>' is a legal character to use in most file systems. If
your programs can't handle it correctly, your programs are broken.
It's trivially simple to write a program that *does* handle it, and blaming
the user for your own refusal to do so is elitism at its worst. It's the
kind of crap that gives rise to the popular stereotype of the "geek know it
all", and I'll have no part of it.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 14 Jan 2005 22:43:10 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: convention regarding lexical filehandles
Message-Id: <slrncuginu.48j.abigail@alexandra.abigail.nl>
Sherm Pendley (spamtrap@dot-app.org) wrote on MMMMCLIV September MCMXCIII
in <URL:news:Fo2dnd_hJogRuXXcRVn-jA@adelphia.com>:
:: Abigail wrote:
::
:: > I remain with my opinion that if you put a '>' in your file name,
:: > you're responsible it doesn't get clobbered.
::
:: The fact is that '>' is a legal character to use in most file systems. If
:: your programs can't handle it correctly, your programs are broken.
And a - is a valid character in most file systems as well. Yet 'rm -r'
doesn't remove the file. Is rm broken?
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Fri, 14 Jan 2005 14:06:05 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: disk space script
Message-Id: <5NudnT1aa8uDhXXcRVn-rg@adelphia.com>
jc8glp1hu wrote:
> am new to the whole forum type / google grouping.
Okay, here's a friendly tip then: This isn't "Google Groups". It's Usenet.
Google is simply a web-based front end to Usenet - and a particularly bad
one at that. If your ISP provides real Usenet access (check their support
pages), you'd be *far* better off using that.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 14 Jan 2005 22:01:24 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Except script error
Message-Id: <5gbgu0t2bm7m3q76ka5ak10fdn3epb1fhg@4ax.com>
On Fri, 14 Jan 2005 13:36:16 +0100, ruud <geen@mail.invalid> wrote:
>#!/usr/bin/perl -w
>use Expect;
Do a favour to yourself and C<use strict;> too. Also C<use warnings;>
is better than -w.
>expect {
> 200}
>
>send "$post\r";
[snip]
>And here is the error:
>syntax error at ./p line 12, near "send"
>Execution of ./p aborted due to compilation errors.
>
>What is wrong with this line ?
>Thanks for your time.
Nothing, but you forgot something _before_ that line. Hint: ";"!
HTH,
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: Fri, 14 Jan 2005 21:19:01 GMT
From: "Noel" <noelt.dolan@virgin.net>
Subject: Re: Except script error
Message-Id: <9HWFd.2531$Pp4.2116@newsfe6-win.ntli.net>
"ruud" <geen@mail.invalid> wrote in message
news:cs8ma9$afr$1@box.nl-netwerken.com...
> Noel wrote:
>
> > # Always use...
> > use strict;
> > use warnings;
> > #... at the start of your code.
> >
> > At the very least your ~expect~ commands seem to be missing the closing
> > semi-colon ~;~. Include these then try it.
>
> I changed is a little bit, but still 1 error left:
> Not enough arguments for send at ./p line 10, near ""post\n")"
>
> Here is the new script:
>
> #!/usr/bin/perl -w
> use Expect;
> use strict;
> use warnings;
> post ("post");
> spawn telnet ("news.nl-netwerken.com 119");
> expect ("200");
> send ("post\n");
> expect ("340");
>
> Thanks for helping me out b.t.w.
> --
> Gr. Ruud
> news://news.nl-netwerken.com
'fraid I don't know this module's usage too well, but hopefully this link
will be of help...
http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod
------------------------------
Date: Fri, 14 Jan 2005 22:44:09 +0100
From: ruud <geen@mail.invalid>
Subject: Re: Except script error
Message-Id: <cs9efb$cfv$1@box.nl-netwerken.com>
Michele Dondi wrote:
>>#!/usr/bin/perl -w
>>use Expect;
>
> Do a favour to yourself and C<use strict;> too. Also C<use warnings;>
> is better than -w.
Hi Michele, can you look at my new script further in this threat ?
I think it is better but still no luck after 2 day's google :-(
I really apreciate your time and knowhow.
--
Gr. Ruud
news://news.nl-netwerken.com
------------------------------
Date: Sat, 15 Jan 2005 08:23:04 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: How to convert MS doc to plain text using Perl on unix
Message-Id: <34qkddF4c50i3U1@individual.net>
"Diandian Zhang" <zhangdidi@hotmail.com> wrote in message
news:7d12548d.0501140046.30cd9f44@posting.google.com...
> Does anyone have an idea, how to do this? Thanks!
Save as a text file in Open Office :-)
------------------------------
Date: Fri, 14 Jan 2005 20:18:39 +0100
From: "PHP2" <nospam@nospam.tv>
Subject: Re: how upload files with Perl using MySQL database
Message-Id: <cs95ub$er7$1@ls219.htnet.hr>
I know it.. but have you some code advice
"Tore Aursand" <toreau@gmail.com> wrote in message
news:3yMFd.4482$Sl3.106474@news4.e.nsc.no...
> PHP2 wrote:
> > i wish that file be uploaded to the one folder on the server and the
path of
> > the image must be added into MySQL database column..
>
> CGI.pm will take care of the file uploading, while the DBI module takes
> care of communicating with the (MySQL) database.
>
>
> --
> Tore Aursand <tore@aursand.no>
> "I didn't have time to write a short letter, so I wrote a long one
> instead." (Mark Twain)
------------------------------
Date: Fri, 14 Jan 2005 14:48:01 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: how upload files with Perl using MySQL database
Message-Id: <tfWdncNEx4pvvHXcRVn-rQ@adelphia.com>
PHP2 wrote:
> I know it.. but have you some code advice
Have you some code? Post it, we'll give you advice concerning it.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 14 Jan 2005 11:52:00 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: how upload files with Perl using MySQL database
Message-Id: <0gklb2x0qt.ln2@goaway.wombat.san-francisco.ca.us>
On 2005-01-14, PHP2 <nospam@nospam.tv> wrote:
> I know it.. but have you some code advice
The code advice in the Posting Guidelines says to post some code and
ask specific questions about what's not working the way you expect.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
------------------------------
Date: Fri, 14 Jan 2005 21:24:26 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: how upload files with Perl using MySQL database
Message-Id: <XTVFd.4543$Sl3.107959@news4.e.nsc.no>
PHP2 wrote:
>>CGI.pm will take care of the file uploading, while the DBI module takes
>>care of communicating with the (MySQL) database.
> I know it.. but have you some code advice
Do you? Have you read the documentation for these modules? Have you
tried searching the web and/or Usenet with Google? What have you tried
so far? Do you expect us to do your work? Do you mind doing others work
for free?
--
Tore Aursand <tore@aursand.no>
"Out of missiles. Out of bullets. Down to harsh language." (Unknown)
------------------------------
Date: 14 Jan 2005 12:50:51 -0800
From: "jc8glp1hu" <jc8glp1hu@gmail.com>
Subject: Re: Log File parser
Message-Id: <1105735851.784171.303600@c13g2000cwb.googlegroups.com>
Sherm Pendly wrote:
>Whoa, hold on a second. Launching a child "grep" process is
unnecessary in
this case, inefficient, and won't even work on many Windows systems.
And
your code does it *twice*.
>Michele was commenting on the code you posted, not on the fact that
you
posted code.
Ok, thanks that makes since. If they would have said that in the first
place it would have been perfect! I thought about opening it within
perl but I wasn't sure which would be more efficient.
Thanks for clarifying!
Cheers!
------------------------------
Date: 14 Jan 2005 21:34:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Log File parser
Message-Id: <cs9dss$htr$1@mamenchi.zrz.TU-Berlin.DE>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > and far older than google groups. Google runs an archive and an
> > interface. That's of great merit,
>
> Well... the archive is of great merit anyway. From what I've seen so far,
> the interface is basically worthless.
That's what I've heard. The mistake is to call a Usenet archive with (of
course) the added ability to post "Google Groups". It's still an archive,
with associated delay, and no replacement for an NNTP server. Never mind
the interface...
Anno
------------------------------
Date: 14 Jan 2005 11:24:03 -0800
From: toomanyjoes@mail.utexas.edu
Subject: Re: Loop through a text file line by line
Message-Id: <1105730643.595937.38990@f14g2000cwb.googlegroups.com>
I'm still having problems opening a file. I looked at the docs and this
is what I came up with.
open (FILE, "> C:\notes\gen.txt") || die ("error $!\n"); #See note 1
while (<FILE>) { #See note 2
s/\<[NR][a\d]\>/ /g #note 3
if (^\w\D\D\s\d+:\d+) #note 4
Note1: Although in all the examples I've looked at the actual file
reference is always very vague and I have never seen a full path with
the files extension in the quotes like I have done here.
Note2: Here I want to loop through the file, is this correct?
Note3: Here I want to find every instance (In the File) of a "<Ra> or a
<N1>(2,3,etc.)" and replace it with nothing (basically remove it)
Note4: Here I'm looking for a specific arrangement of characters at the
beginning of the line it can be any character followed by 2 letters
followed by a space followed by any number of digits separated by a
colon. (ex. 1RA 12321:123214 would match as well as ADD 4:2) if a match
occurs I want to remove the colon and separate these items with a
delimiter. For Example (ex. 1RA/ 12321/123214)
And thats as far as I've been able to get because I get an error
opening the file. It looks to me like I've done it by the book. But I
must be missing something. I'd appreciate any comments about my code.
Thanks,
Joe
Martin Kissner wrote:
> Michele Dondi wrote :
> > On 14 Jan 2005 10:24:09 GMT, Martin Kissner <news@chaos-net.de>
wrote:
> >
> >>> Not exactly. From 'perldoc perlop':
> >>> [...]
> >>
> >>In <yzdu0ponibh.fsf@invalid.net> Arndt wrote to me:
> >>| The "diamond" operator <> is described in perlop and perlopentut.
> >>| You read from STDIN by using the normal Unix syntax:
> >>|
> >>| ./myperlscript.pl < file
> >>
> >>This worked for me.
> >
> > So what?!?
>
> I was not sure if I have expressed myself correctly so tried to clear
> up what I meant.
>
> --
> Epur Si Muove (Gallileo Gallilei)
------------------------------
Date: 14 Jan 2005 11:25:23 -0800
From: toomanyjoes@mail.utexas.edu
Subject: Re: Loop through a text file line by line
Message-Id: <1105730722.968966.263240@c13g2000cwb.googlegroups.com>
I'm still having problems opening a file. I looked at the docs and this
is what I came up with.
open (FILE, "> C:\notes\gen.txt") || die ("error $!\n"); #See note 1
while (<FILE>) { #See note 2
s/\<[NR][a\d]\>/ /g #note 3
if (^\w\D\D\s\d+:\d+) #note 4
Note1: Although in all the examples I've looked at the actual file
reference is always very vague and I have never seen a full path with
the files extension in the quotes like I have done here.
Note2: Here I want to loop through the file, is this correct?
Note3: Here I want to find every instance (In the File) of a "<Ra> or a
<N1>(2,3,etc.)" and replace it with nothing (basically remove it)
Note4: Here I'm looking for a specific arrangement of characters at the
beginning of the line it can be any character followed by 2 letters
followed by a space followed by any number of digits separated by a
colon. (ex. 1RA 12321:123214 would match as well as ADD 4:2) if a match
occurs I want to remove the colon and separate these items with a
delimiter. For Example (ex. 1RA/ 12321/123214)
And thats as far as I've been able to get because I get an error
opening the file. It looks to me like I've done it by the book. But I
must be missing something. I'd appreciate any comments about my code.
Thanks,
Joe
Martin Kissner wrote:
> Michele Dondi wrote :
> > On 14 Jan 2005 10:24:09 GMT, Martin Kissner <news@chaos-net.de>
wrote:
> >
> >>> Not exactly. From 'perldoc perlop':
> >>> [...]
> >>
> >>In <yzdu0ponibh.fsf@invalid.net> Arndt wrote to me:
> >>| The "diamond" operator <> is described in perlop and perlopentut.
> >>| You read from STDIN by using the normal Unix syntax:
> >>|
> >>| ./myperlscript.pl < file
> >>
> >>This worked for me.
> >
> > So what?!?
>
> I was not sure if I have expressed myself correctly so tried to clear
> up what I meant.
>
> --
> Epur Si Muove (Gallileo Gallilei)
------------------------------
Date: Fri, 14 Jan 2005 14:44:19 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Loop through a text file line by line
Message-Id: <tfWdncFEx4qJvHXcRVn-rQ@adelphia.com>
toomanyjoes@mail.utexas.edu wrote:
> I'm still having problems opening a file. I looked at the docs and this
> is what I came up with.
>
> open (FILE, "> C:\notes\gen.txt") || die ("error $!\n"); #See note 1
First, backslashes have special meaning in double-quoted strings. You're on
Windows obviously, so you have options. You could "escape" the backslashes
by doubling them like this:
"C:\\notes\\gen.txt"
Or, you could use standard forward slashes - Windows understands them just
fine:
"C:/notes/gen.txt"
And last but *certainly* not least, why use double-quotes at all? You don't
need to. In die() you *do* need them, because you're interpolating the
value of $! into a string - but in open() you're not doing that, so you
should be using single quotes:
'C:\notes\gen.txt'
Have a look at "perldoc perlop" for more.
You should be using the three-argument form of open, where the mode and file
name are separate:
open (FILE, '>', 'C:\notes\gen.txt') or die(...);
Have a look at "perldoc perlopentut" for more. And note that '>' is used to
open a file for *output*. You want to open the file for input, so you
should be using '<'.
> while (<FILE>) { #See note 2
> Note2: Here I want to loop through the file, is this correct?
Well, it *would* be correct if FILE had been opened for input. With each
iteration of the while() loop, a line is read from the file and assigned to
$_. If you wanted to use an explicit variable, rather than the implicit $_,
you could write it like this:
while (my $line = <FILE>) {
> And thats as far as I've been able to get because I get an error
> opening the file.
I'm guessing the error looks something like this:
File C:
otesgen.txt does not exist
In a double-quoted string, "\n" is a newline. "\g" has no special meaning I
can think of offhand, so it's interpreted as just a "g". Obviously, the
filename doesn't have a newline in it - which is why you need to escape the
backslashes, or better still don't use them at all, or use single quotes.
(BTW, I shouldn't have to guess at the error message. As the posting
guidelines point out, you should post the full text of any error
messages...)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 14 Jan 2005 14:49:10 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Loop through a text file line by line
Message-Id: <tfWdncJEx4qrv3XcRVn-rQ@adelphia.com>
toomanyjoes@mail.utexas.edu wrote:
> I'm still having problems opening a file. I looked at the docs and this
> is what I came up with.
Yeah, yeah, we get it. We heard you the FIRST TWO times you posted this.
Once is enough, really.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 14 Jan 2005 11:19:34 -0800
From: WCR.III@gmail.com
Subject: Math::NumberCruncher-5.00 bug
Message-Id: <1105730374.312978.238500@c13g2000cwb.googlegroups.com>
Just a note to stuff this into the 'net consciousness, since I
can't find it mentioned anywhere else.
The SignSignificance calculation in Math::NumberCruncher
has a bug.
currently the code looks like this:
> my ( $trials, $hits, $probability ) = @_;
> return undef unless defined $trials && defined $hits &&
> defined $probability;
> my $confidence;
> foreach ( $hits .. $trials ) {
> $confidence += Binomial( $trials, $hits, $probability );
> }
> return $confidence;
Unfortunately, the confidence isn't calculated properly - the
middle operand to Binomial needs to iterate from $hits to $trials.
To fix, do something like this instead:
> my ( $trials, $hits, $probability ) = @_;
> return undef unless defined $trials && defined $hits &&
> defined $probability;
> my ($confidence, $ahit, $aconf);
> $confidence = 0;
> foreach ($ahit = $hits;$ahit <= $trials;$ahit++)
> {
> $aconf = Binomial( $trials, $ahit, $probability );
># print STDERR "numcrunch binomial returns: $hits $ahit $trials
$aconf\n";
> $confidence += $aconf;
> }
> return $confidence;
Yes, it's clunky and looks like C by Perl standards. It also
doesn't have bugs introduced because implied automatic
variables are being (mis) used :-)
I informed the module maintainer of this problem some time
ago, but a recent re-install of the module demonstrated that
the fix hadn't made it into the code yet.
Just another C hacker...
Will Ray
------------------------------
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 7650
***************************************