[18217] in Perl-Users-Digest
Perl-Users Digest, Issue: 385 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 1 09:07:26 2001
Date: Thu, 1 Mar 2001 06: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)
Message-Id: <983455515-v10-i385@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 1 Mar 2001 Volume: 10 Number: 385
Today's topics:
Re: Attachments <djberge@uswest.com>
Re: Bug report: splice/stringification <pne-news-20010301@newton.digitalspace.net>
Re: dereferencing an array of references using join (Tad McClellan)
Re: Display Delay in Perl? (Anno Siegel)
Re: Display Delay in Perl? <wyzelli@yahoo.com>
Re: Display Delay in Perl? (Rafael Garcia-Suarez)
Re: Display Delay in Perl? (Anno Siegel)
Re: Display Delay in Perl? (Abigail)
Re: Display Delay in Perl? (Anno Siegel)
extracting e-mail addresses from text file database <steevedu@mondenet.com>
Re: extracting e-mail addresses from text file database <tom@power.net.uk>
File locking problem? <vautourNO@SPAMunb.ca>
fork and a file descriptor on solaris <sorry.noq@mail.adr>
how to print a \ <Waarddebon@chello.nl>
Re: how to print a \ <wyzelli@yahoo.com>
Re: how to print a \ <peter.s@tjgroup.dk>
Re: how to print a \ <wyzelli@yahoo.com>
Re: how to print a \ <peter.s@tjgroup.dk>
Re: Newbie question re: Perl on RedHat 7 (Anno Siegel)
Re: Perl string <Bob@Morane.com>
Re: print "</tr><tr>" vs. print $tr <flavell@mail.cern.ch>
Re: print "</tr><tr>" vs. print $tr <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 01 Mar 2001 07:57:31 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: Attachments
Message-Id: <3A9E554B.B0A64C51@uswest.com>
Todd Anderson wrote:
> Dear Sirs,
> I use the code below to send email with attachments. However when
> sending to more than 1 recipient, the code does not recognize the new
> "$to" and sends the second email to the first recipient. So the first
> recipient gets 2 emails. And then some times on the second email the
> attachment file appears to be empty and so it doesn't get attached. Any
> ideas?
> Thanks in advance for your help.
>
> ##########
> sub send_email{
>
> use MIME::Base64 qw(encode_base64); #Attachements
>
> my %mime =
> (
> #-------------------------------------<TEXT>-----
> 'HTML',"text/html",
> 'HTM',"text/html",
> 'STM',"text/html",
> 'SHTML',"text/html",
> 'TXT',"text/plain",
> 'PREF',"text/plain",
> 'AIS',"text/plain",
> 'RTX',"text/richtext",
> 'TSV',"text/tab-separated-values",
> 'NFO',"text/warez-info",
> 'ETX',"text/x-setext",
> 'SGML',"text/x-sgml",
> 'SGM',"text/x-sgml",
> 'TALK',"text/x-speech",
> 'CGI',"text/plain",
> 'PL',"text/plain",
> #-------------------------------------<IMAGE>----
> 'COD', "image/cis-cod",
> 'FID', "image/fif",
> 'GIF', "image/gif",
> 'ICO', "image/ico",
> 'IEF', "image/ief",
> 'JPEG', "image/jpeg",
> 'JPG', "image/jpeg",
> 'JPE', "image/jpeg",
> 'PNG', "image/png",
> 'TIF', "image/tiff",
> 'TIFF', "image/tiff",
> 'MCF',"image/vasa",
> 'RAS',"image/x-cmu-raster",
> 'CMX',"image/x-cmx",
> 'PCD',"image/x-photo-cd",
> 'PNM',"image/x-portable-anymap",
> 'PBM',"image/x-portable-bitmap",
> 'PGM',"image/x-portable-graymap",
> 'PPM',"image/x-portable-pixmap",
> 'RGB',"image/x-rgb",
> 'XBM',"image/x-xbitmap",
> 'XPM',"image/x-xpixmap",
> 'XWD',"image/x-xwindowdump",
> #-------------------------------------<APPS>-----
> 'EXE',"application/octet-stream",
> 'BIN',"application/octet-stream",
> 'DMS',"application/octet-stream",
> 'LHA',"application/octet-stream",
> 'CLASS',"application/octet-stream",
> 'DLL',"application/octet-stream",
> 'AAM',"application/x-authorware-map",
> 'AAS',"application/x-authorware-seg",
> 'AAB',"application/x-authorware-bin",
> 'VMD',"application/vocaltec-media-desc",
> 'VMF',"application/vocaltec-media-file",
> 'ASD',"application/astound",
> 'ASN',"application/astound",
> 'DWG',"application/autocad",
> 'DSP',"application/dsptype",
> 'DFX',"application/dsptype",
> 'EVY',"application/envoy",
> 'SPL',"application/futuresplash",
> 'IMD',"application/immedia",
> 'HQX',"application/mac-binhex40",
> 'CPT',"application/mac-compactpro",
> 'DOC',"application/msword",
> 'ODA',"application/oda",
> 'PDF',"application/pdf",
> 'AI',"application/postscript",
> 'EPS',"application/postscript",
> 'PS',"application/postscript",
> 'PPT',"application/powerpoint",
> 'RTF',"application/rtf",
> 'APM',"application/studiom",
> 'XAR',"application/vnd.xara",
> 'ANO',"application/x-annotator",
> 'ASP',"application/x-asap",
> 'CHAT',"application/x-chat",
> 'BCPIO',"application/x-bcpio",
> 'VCD',"application/x-cdlink",
> 'TGZ',"application/x-compressed",
> 'Z',"application/x-compress",
> 'CPIO',"application/x-cpio",
> 'PUZ',"application/x-crossword",
> 'CSH',"application/x-csh",
> 'DCR',"application/x-director",
> 'DIR',"application/x-director",
> 'DXR',"application/x-director",
> 'FGD',"application/x-director",
> 'DVI',"application/x-dvi",
> 'LIC',"application/x-enterlicense",
> 'EPB',"application/x-epublisher",
> 'FAXMGR',"application/x-fax-manager",
> 'FAXMGRJOB',"application/x-fax-manager-job",
> 'FM',"application/x-framemaker",
> 'FRAME',"application/x-framemaker",
> 'FRM',"application/x-framemaker",
> 'MAKER',"application/x-framemaker",
> 'GTAR',"application/x-gtar",
> 'GZ',"application/x-gzip",
> 'HDF',"application/x-hdf",
> 'INS',"application/x-insight",
> 'INSIGHT',"application/x-insight",
> 'INST',"application/x-install",
> 'IV',"application/x-inventor",
> 'JS',"application/x-javascript",
> 'SKP',"application/x-koan",
> 'SKD',"application/x-koan",
> 'SKT',"application/x-koan",
> 'SKM',"application/x-koan",
> 'LATEX',"application/x-latex",
> 'LICMGR',"application/x-licensemgr",
> 'MAILPIPE',"application/x-mailfolder",
> 'MIF',"application/x-mailfolder",
> 'NC',"application/x-netcdf",
> 'CDF',"application/x-netcdf",
> 'SDS',"application/x-onlive",
> 'SGI-LPR',"application/x-sgi-lpr",
> 'SH',"application/x-sh",
> 'SHAR',"application/x-shar",
> 'SWF',"application/x-shockwave-flash",
> 'SPRITE',"application/x-sprite",
> 'SPR',"application/x-sprite",
> 'SIT',"application/x-stuffit",
> 'SV4CPIO',"application/x-sv4cpio",
> 'SV4CRC',"application/x-sv4crc",
> 'TAR',"application/x-tar",
> 'TARDIST',"application/x-tardist",
> 'TCL',"application/x-tcl",
> 'TEX',"application/x-tex",
> 'TEXINFO',"application/x-texinfo",
> 'TEXI',"application/x-texinfo",
> 'T',"application/x-troff",
> 'TR',"application/x-troff",
> 'TROFF',"application/x-troff",
> 'MAN',"application/x-troff-man",
> 'ME',"application/x-troff-me",
> 'MS',"application/x-troff-ms",
> 'TVM',"application/x-tvml",
> 'TVM',"application/x-tvml",
> 'USTAR',"application/x-ustar",
> 'SRC',"application/x-wais-source",
> 'WKZ',"application/x-wingz",
> 'ZIP',"application/x-zip-compressed",
> 'ZTARDIST',"application/x-ztardist",
> #-------------------------------------<AUDIO>----
> 'AU',"audio/basic",
> 'SND',"audio/basic",
> 'ES',"audio/echospeech",
> 'MID',"audio/midi",
> 'KAR',"audio/midi",
> 'MPGA',"audio/mpeg",
> 'MP2',"audio/mpeg",
> 'TSI',"audio/tsplayer",
> 'VOX',"audio/voxware",
> 'AIF',"audio/x-aiff",
> 'AIFC',"audio/x-aiff",
> 'AIFF',"audio/x-aiff",
> 'MID',"audio/x-midi",
> 'MP3',"audio/x-mpeg",
> 'MP2A',"audio/x-mpeg2",
> 'MPA2',"audio/x-mpeg2",
> 'M3U',"audio/x-mpegurl",
> 'MP3URL',"audio/x-mpegurl",
> 'PAT',"audio/x-pat",
> 'RAM',"audio/x-pn-realaudio",
> 'RPM',"audio/x-pn-realaudio-plugin",
> 'RA',"audio/x-realaudio",
> 'SBK',"audio/x-sbk",
> 'STR',"audio/x-str",
> 'WAV',"audio/x-wav",
> #-------------------------------------<VIDEO>----
> 'MPEG',"video/mpeg",
> 'MPG',"video/mpeg",
> 'MPE',"video/mpeg",
> 'QT',"video/quicktime",
> 'MOV',"video/quicktime",
> 'VIV',"video/vivo",
> 'VIVO',"video/vivo",
> 'MPS',"video/x-mpeg-system",
> 'SYS',"video/x-mpeg-system",
> 'MP2V',"video/x-mpeg2",
> 'MPV2',"video/x-mpeg2",
> 'AVI',"video/x-msvideo",
> 'MV',"video/x-sgi-movie",
> 'MOVIE',"video/x-sgi-movie",
> #-------------------------------------<EXTRA>----
> 'PDB',"chemical/x-pdb",
> 'XYZ',"chemical/x-pdb",
> 'CHM',"chemical/x-cs-chemdraw",
> 'SMI',"chemical/x-daylight-smiles",
> 'SKC',"chemical/x-mdl-isis",
> 'MOL',"chemical/x-mdl-molfile",
> 'RXN',"chemical/x-mdl-rxn",
> 'SMD',"chemical/x-smd",
> 'ACC',"chemical/x-synopsys-accord",
> 'ICE',"x-conference/x-cooltalk",
> 'SVR',"x-world/x-svr",
> 'WRL',"x-world/x-vrml",
> 'VRML',"x-world/x-vrml",
> 'VRJ',"x-world/x-vrt",
> 'VRJT',"x-world/x-vrt",
> );
>
> $sender = "$user\@$Serv";
>
> open (MAILPIPE,"|$sendmail $to") || order_error("Sorry! There's a big
> line at the post office. Try again in a minute");
>
> $message_header .= "From: $sender\n";
> $message_header .= "To: $to\n";
> $message_header .= "Subject: $form_data{'subj'}\n";
> $message_header .= "Date: " . SentDate() . "\n";
> $message_header .= "X-Mailer: \"$program_name\"\n";
>
> $message_header .= "MIME-Version: 1.0\n";
> $message_header .= "Content-Type: multipart/mixed;\n";
> $boundary = "a_=docuharbor-=_fax.document=--" . time;
> $message_header .= "\tboundary=\"$boundary\"\n";
>
> print MAILPIPE "$message_header\n";
>
> $temp = "This is a MIME encoded message.\n\n";
> $temp .= "--$boundary\n";
> $temp .= "Content-Type: text/plain;
> charset=\"US-ASCII\"\n\n$form_data{'message'}\n";
>
> print MAILPIPE $temp;
>
> foreach $attachment (@document_name){#######################
>
> $attachment =~ s/.*?([^\\\/:]+)$/$1/;
>
> $full_path =
> "$path/members/$session_username/$form_data{'db_id'}/$attachment";
>
> next unless (-e $full_path); # make sure it's there
>
> if (-T $full_path) {
> open (ATTACH,"<$full_path") or next; # if open fails, go to next one
>
> $temp = "--$boundary\n";
> $type = 'plain';
> $attachment =~ /.*\.(.*)$/;
> if ($1 =~ /^htm/) {
> $type = 'html';
> }
> $temp .= "Content-Type: text/$type;\n\tname=\"$attachment\"\n";
> $temp .= "Content-Disposition:
> inline;\n\tfilename=\"$attachment\"\n";
> $temp .= "\n";
>
> print MAILPIPE $temp;
>
> while (<ATTACH>) {
>
> print MAILPIPE $_;
>
> }
> close ATTACH;
>
> print MAILPIPE \n;
>
> }
> else {# it's not a text file
>
> open (ATTACH,"<$full_path") or next;
> $temp = "";
> $temp .= "--$boundary\n";
> $attachment =~ /[^.]*\.(.*)$/;
> $type = $mime{$1} || 'application/x-whatever';
>
> $temp .= "Content-Type: $type;\n\tname=\"$attachment\"\n";
> $temp .= "Content-Disposition:
> inline;\n\tfilename=\"$attachment\"\n";
> $temp .= "Content-Transfer-Encoding: base64\n";
> $temp .= "\n";
>
> print MAILPIPE $temp || order_error("Can not print mail pipe1");
>
> $temp = "";
> while (read(ATTACH, $buf, 60*57)) {
>
> $temp .= encode_base64($buf); # Code it up baby
> }
> close ATTACH;
> print MAILPIPE "$temp,\n" || order_error("Can not print mail
> pipe2");
>
> }
>
> print MAILPIPE "--$boundary--" || order_error("Can not print mail
> pipe3");
>
> print MAILPIPE "\n" || order_error("Can not print mail pipe5");
> }#foreach#######################################
>
> print MAILPIPE "\n.\n" || order_error("Can not print mail pipe4");
>
> close MAILPIPE || order_error("Can not close mail pipe1");
>
> $full_path = "";
> $to = "";
> }
> #########
Might I suggest the "Mail::Sender" module on CPAN. Worked like
a charm for me.
Dan
------------------------------
Date: Thu, 01 Mar 2001 14:41:11 +0100
From: Philip Newton <pne-news-20010301@newton.digitalspace.net>
Subject: Re: Bug report: splice/stringification
Message-Id: <n9ks9tk5rl9pi94k18fm4mdcuicpa6mmd0@4ax.com>
On Thu, 01 Mar 2001 01:29:07 GMT, mgjv@tradingpost.com.au (Martien
Verbruggen) wrote:
> It wasn't me!
>
> I don't even own a site with freely downloadable cracked versions of
> commercial software. I also don't really know about a working pyramid
> scheme, and I don't know how to add inches to your penis. Furthermore,
> I can't help you get rich, [etc. etc.]
Ah, I see -- you're seeling laser printer toner! (Or maybe herbal
Vi*gr* alternatives.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 1 Mar 2001 07:53:10 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: dereferencing an array of references using join
Message-Id: <slrn99shhl.l7k.tadmc@tadmc26.august.net>
[ Please put your comments *following* the quoted text that you
are commenting on, as is the convention here. Thanks.
Jeopardectomy performed.
]
Joe Williams <joeykid6@yahoo.com> wrote:
>Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in message
>news:97ik65$1d7$1@mamenchi.zrz.TU-Berlin.DE...
>> According to Joe Williams <joeykid6@yahoo.com>:
>> > Thanks, Ren. For some reason, I thought I tested without the quotes and
>got
>> > an error. You win for the most concise code and the least impatient
>> > response....
>>
>> Do you realise how arrogant that sounds?
>Sorry, didn't mean to be arrogant. One of the responses I got told me to
>keep useless stuff out of my code, which just struck me the wrong way
Keeping useless stuff out of your code makes your code better,
for the reason given with the original comment.
>since
>I'd mentioned I was new to programming perl.
New Perl programmers want better code too.
How does being new to Perl have an effect on the
applicability of the comment?
I cannot find anything impatient in my followup.
>No offense meant.
I'll take your address back out then.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 Mar 2001 11:18:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Display Delay in Perl?
Message-Id: <97lb5c$7st$2@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Ranjithalingam Camalalingam (ranch@lager.engsoc.carleton.ca) wrote on
[...]
> {} I want each letter in "Hello World" to appear after 1 second delay....
>
> Turn buffering off:
>
> perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
Gee, you can give this special twist to just any program. What if
you want a two-second delay? Oh, I know, override print().
Anno
------------------------------
Date: Thu, 1 Mar 2001 21:01:10 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Display Delay in Perl?
Message-Id: <Wpqn6.7$UL1.2130@vic.nntp.telstra.net>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:97lb5c$7st$2@mamenchi.zrz.TU-Berlin.DE...
> >
> > perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
>
> Gee, you can give this special twist to just any program. What if
> you want a two-second delay? Oh, I know, override print().
perl -we '$| = 1; map {sleep 2, print} "Hello" =~ /./g'
Works for me... but you were just kidding... :)
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Thu, 01 Mar 2001 11:39:01 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Display Delay in Perl?
Message-Id: <slrn99sd61.4l7.rgarciasuarez@rafael.kazibao.net>
Anno Siegel wrote in comp.lang.perl.misc:
>
> > perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
>
> Gee, you can give this special twist to just any program. What if
> you want a two-second delay? Oh, I know, override print().
You can't override print, can you? I think it's one of the few builtins
that can't be overriden.
#!/usr/local/bin/perl
package foo;
require Exporter;
@ISA = qw/Exporter/;
@EXPORT_OK = qw/print/;
use subs 'print';
sub print { print "<@_>\n"; }
package main;
foo -> import ('print');
print("bar");
&print("bar");
__END__
Outputs :
bar<bar>
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 1 Mar 2001 11:45:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Display Delay in Perl?
Message-Id: <97lco2$7st$3@mamenchi.zrz.TU-Berlin.DE>
According to Wyzelli <wyzelli@yahoo.com>:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:97lb5c$7st$2@mamenchi.zrz.TU-Berlin.DE...
> > >
> > > perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
> >
> > Gee, you can give this special twist to just any program. What if
> > you want a two-second delay? Oh, I know, override print().
>
> perl -we '$| = 1; map {sleep 2, print} "Hello" =~ /./g'
>
> Works for me... but you were just kidding... :)
It works, but it takes away that special twist of using the return
value of print() as the argument to sleep().
Anno
------------------------------
Date: 1 Mar 2001 11:52:16 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Display Delay in Perl?
Message-Id: <slrn99sdvg.eh.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCXXXIX
September MCMXCIII in <URL:news:97lb5c$7st$2@mamenchi.zrz.TU-Berlin.DE>:
// According to Abigail <abigail@foad.org>:
// > Ranjithalingam Camalalingam (ranch@lager.engsoc.carleton.ca) wrote on
//
// [...]
//
// > {} I want each letter in "Hello World" to appear after 1 second delay....
// >
// > Turn buffering off:
// >
// > perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
//
// Gee, you can give this special twist to just any program. What if
// you want a two-second delay? Oh, I know, override print().
perl -we '$| = 1; map {sleep sleep print} "Hello" =~ /./g'
HTH. HAND.
Abigail
--
perl -wlne '}print$.;{' file # Count the number of lines.
------------------------------
Date: 1 Mar 2001 11:56:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Display Delay in Perl?
Message-Id: <97ldda$7st$4@mamenchi.zrz.TU-Berlin.DE>
According to Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
> Anno Siegel wrote in comp.lang.perl.misc:
> >
> > > perl -we '$| = 1; map {sleep print} "Hello" =~ /./g'
> >
> > Gee, you can give this special twist to just any program. What if
> > you want a two-second delay? Oh, I know, override print().
>
> You can't override print, can you? I think it's one of the few builtins
> that can't be overriden.
I guess you're right. I wasn't sure myself but didn't care to check
for this little quip. Thanks for the correction.
Come to think of it, I seem to remember there is a simple way to tell
if a builtin can be overridden, short of testing if it works. Can
someone remind me, or am I dreaming?
[proof of non-overridability snipped]
Anno
------------------------------
Date: Thu, 01 Mar 2001 12:55:14 GMT
From: "Steeve Duchesne" <steevedu@mondenet.com>
Subject: extracting e-mail addresses from text file database
Message-Id: <SErn6.9393$f5.884951@news>
Hello everybody,
I want to dynamically populate a simple text file database from entries in a
form using Perl. This file will contain e-mail addresses, names and other
types of data. The information will be kept as lines separated by tabs or
pipes. My question is: Is there a simple way of extracting e-mail addresses
without extracting all the other data? Also, lets say that the e-mail
addresses are placed at the beginning of each line. Is it possible to
extract the information that comes with a particular address, if so how can
I get my program to do this?
------------------------------
Date: Thu, 01 Mar 2001 12:59:46 +0000
From: Tom Scheper <tom@power.net.uk>
Subject: Re: extracting e-mail addresses from text file database
Message-Id: <9ths9tg4t237dubuo989sasdpef89hr57c@4ax.com>
On Thu, 01 Mar 2001 12:55:14 GMT, "Steeve Duchesne"
<steevedu@mondenet.com> shed a beam of light on us:
>Hello everybody,
>
>I want to dynamically populate a simple text file database from entries in a
>form using Perl. This file will contain e-mail addresses, names and other
>types of data. The information will be kept as lines separated by tabs or
>pipes. My question is: Is there a simple way of extracting e-mail addresses
>without extracting all the other data? Also, lets say that the e-mail
>addresses are placed at the beginning of each line. Is it possible to
>extract the information that comes with a particular address, if so how can
>I get my program to do this?
It is, but can you post a few sample lines from the database text
file?
-=Cornelis
------------------------------
Date: Thu, 01 Mar 2001 09:13:39 -0400
From: Gil Vautour <vautourNO@SPAMunb.ca>
Subject: File locking problem?
Message-Id: <3A9E4B03.1AF49CC6@SPAMunb.ca>
Hello,
I have a CGI script in Perl that uses a performs a simple counter
operation, when a user submits a Form, a file is opened, the value is
read and incremented by one and written back to file. Occasionally the
counter gets reset back to 1 for some reason. Below is a snippet of the
code I use, could this be some sort of file locking problem?
Perhaps there is a better way to do this?
open(LASTNUM, "./counter/$counter") || die "ERROR! can't open file:
$!\n";
$num = <LASTNUM>;
chop($num);
close(LASTNUM) || die "ERROR! can't close file: $!\n";
$num++;
open(STUDFILE, ">./counter/$counter") || die "ERROR! can't open
file: $!\n";
print STUDFILE "$num\n";
close(STUDFILE) || die "ERROR! can't close file: $!\n";
------------------------------
Date: Thu, 01 Mar 2001 13:07:58 +0100
From: Ingo Reise <sorry.noq@mail.adr>
Subject: fork and a file descriptor on solaris
Message-Id: <3A9E3B9E.9B34ACD1@mail.adr>
Hi all together!
On a Sun Ultra 10 running SunOS xxxx 5.6 Generic_105181-23 sun4u sparc
SUNW,Ultra-5_10 i've a small file containing 5 lines with senseless
content (line x).
My Perl-Program reads this file and for every line starts a child doing
nothing:
#!/home/dingo/bin/perl -w
sub startChild {
$child_pid=fork;
if($child_pid==0) {
# print("This is child $$ doing really nothing\n");
exit;
} else {
return $child_pid;
}
}
open(IN,"dummy.txt") || die "Error :$!";
my $line;
while ($line = <IN>) {
chomp $line;
print "read >$line< by pid $$\n";
startChild();
}
close(IN);
(I know there is no error checking for fork, but i shortened the program
to the essentials)
The output of this is:
read >line 1< by pid 8817
read >line 2< by pid 8817
read >line 3< by pid 8817
read >line 4< by pid 8817
read >line 5ine 1< by pid 8817
read >line 2< by pid 8817
read >line 3< by pid 8817
read >line 4< by pid 8817
read >line 5line 2< by pid 8817
read >line 3< by pid 8817
read >line 4< by pid 8817
read >line 5< by pid 8817
EOF
It looks like the IN file descriptor is changed in someway when the
child "exit"s.
Ths does not happen, when the childs are exiting after the main branch
(insert "sleep 1" before the exit).
What happens to IN when the child exits, and how to avoid this???
(On a linux-machine everything seems to be alright)
Thanks for your help,
Ingo Reise
------------------------------
Date: Thu, 01 Mar 2001 11:19:55 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: how to print a \
Message-Id: <vfqn6.1696119$%C1.22213429@Flipper>
I'm trying to print a string which also has a \ in it, but somehow it
doesn't display the \ character.
How can I solve this ?
$name="cgi-bin\ddd.pl";
------------------------------
Date: Thu, 1 Mar 2001 20:56:28 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: how to print a \
Message-Id: <xlqn6.6$UL1.2063@vic.nntp.telstra.net>
"Waarddebon" <Waarddebon@chello.nl> wrote in message
news:vfqn6.1696119$%C1.22213429@Flipper...
> I'm trying to print a string which also has a \ in it, but somehow it
> doesn't display the \ character.
> How can I solve this ?
>
> $name="cgi-bin\ddd.pl";
>
single quote the string, escape the backslash, or use a forward slash.
$name = 'cgi-bin\add.pl'; # should work OK
$name = 'cgi-bin/add.pl'; #yes this will work OK on windows. simpler, and
probably good to use by default
$name = "cgi-bin/add.pl"; # works on all platforms, suitable where
interpolation is needed
$name = "cgi-bin\\add.pl"; #yucky, and double quotes not needed if no
interpolation needed.
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Thu, 1 Mar 2001 12:34:17 +0100
From: "Peter Søgaard" <peter.s@tjgroup.dk>
Subject: Re: how to print a \
Message-Id: <97lbt3$pe2$1@news.inet.tele.dk>
you have to escape the \...
print "cgi-bin\\ddd.pl";
will print out "cgi-bin/ddd.pl"
------------------------------
Date: Thu, 1 Mar 2001 21:02:04 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: how to print a \
Message-Id: <Nqqn6.8$UL1.2085@vic.nntp.telstra.net>
"Peter Søgaard" <peter.s@tjgroup.dk> wrote in message
news:97lbt3$pe2$1@news.inet.tele.dk...
> you have to escape the \...
>
> print "cgi-bin\\ddd.pl";
> will print out "cgi-bin/ddd.pl"
>
By what mechanism does an escaped backslash become a forward slash? :)
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Thu, 1 Mar 2001 12:38:06 +0100
From: "Peter Søgaard" <peter.s@tjgroup.dk>
Subject: Re: how to print a \
Message-Id: <97lc4b$q0u$1@news.inet.tele.dk>
hehe, ooops..got me....anyway your suggestions in the post above is much
better than escaping the \...so just disregard post ;)
------------------------------
Date: 1 Mar 2001 14:00:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie question re: Perl on RedHat 7
Message-Id: <97lklb$jbv$1@mamenchi.zrz.TU-Berlin.DE>
According to Danny C. <no@thanks.moo>:
> mwhyte_@_pmds.com spluttered this in <97jjve$5c9$1@news.netmar.com>:
>
> >When I run "perl hello.pl", everything is fine. However, after making
> >it executable, I can't run it simply by typing "hello". Am I missing a
> >step in making it executable (the book I'm reading said all that was
> >necessary was to add the "#!/usr/bin/perl -w" line at the beginning and
> >run a simple chmod)?
>
> The file is not named "hello", it's named "hello.pl".
>
> Try running "hello.pl" (no quotes, of course)
... or indeed "./hellp.pl" to cover all bases. Not everyone has
"." on their path and some who do probably shouldn't.
Anno
------------------------------
Date: Thu, 1 Mar 2001 10:02:18 -0000
From: "L'Ombre Jaune" <Bob@Morane.com>
Subject: Re: Perl string
Message-Id: <3a9e2cb8_2@nnrp1.news.uk.psi.net>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:97ji6m$6s7$2@mamenchi.zrz.TU-Berlin.DE...
> According to Tad McClellan <tadmc@augustmail.com>:
> > Peter Søgaard <peter.s@tjgroup.dk> wrote:
> > >> What are "inverted commas"?
> > >
> > >I think he means back ticks ``
> > >...not sure tho'
> >
> >
> > But there were not any backtick characters in his post...
>
> Uh... "inverted commas" is a britishism for "double quotes".
>
> Anno
'britishism'? I think not! Just plain English. You know, the one that you
get taught at school. Yes mate!
L'Ombre Jaune
------------------------------
Date: Thu, 1 Mar 2001 14:17:51 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <Pine.LNX.4.30.0103011406590.4620-100000@lxplus003.cern.ch>
On Wed, 28 Feb 2001, Stan McCann wrote:
> > Did you even try? Although "cgi.pm" isn't really correct, suppose we
>
> Yes, I did try.
You claim to be a seasoned usenaut, yet you seem blissfully unaware
that on usenet you are nothing more than what you choose to type.
You could get yourself a better hearing and more-useful advice if you
would show what you have tried already. Maybe you overlooked
something that others thought to be obvious and therefore wouldn't
bother to mention.
> I also know that cgi.pm isn't correct, I'm a lazy typer
> and only use caps when I have to.
This was such an occasion.
> > It's a normal courtesy to the regulars on any usenet group to
> > familiarise yourself with their FAQs first. Nobody minds if you
> > missed something that you needed, but at least if you show some
> > evidence of having tried, you'll command a lot more sympathy.
>
> I do not need lessons in usenet etiquette,
I'll happily leave the verdict on that question to the regulars around
here.
> You seem to be the only one that has a problem with my post.
Again, I'm content to leave that question to the regulars to comment
on; I'm entirely accustomed to a robust style of discussion on usenet,
and unlikely to make any major changes in that regard. but the last
thing I would want to do would be to offer misleading advice to
others. As such, I take seriously all feedback from the respected
group regulars.
bye.
------------------------------
Date: Thu, 01 Mar 2001 13:56:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <38ls9t4epls0mcc40224pdthteb3rtcl48@4ax.com>
Stan McCann wrote:
> I also know that cgi.pm isn't correct, I'm a lazy typer
>and only use caps when I have to.
How are you gonna survive as a programmer in a case sensitive language,
with this attitude?
In other words: you have to. Not for us, but Perl cares.
--
Bart.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 385
**************************************