[22521] in Perl-Users-Digest
Perl-Users Digest, Issue: 4742 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 21 21:06:06 2003
Date: Fri, 21 Mar 2003 18:05: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 Fri, 21 Mar 2003 Volume: 10 Number: 4742
Today's topics:
Re: creating an error box <goldbb2@earthlink.net>
Re: doubts on \n <goldbb2@earthlink.net>
Re: doubts on \n <goldbb2@earthlink.net>
Re: How can I....? <goldbb2@earthlink.net>
Re: How to include data stamps in a script?? <tore@aursand.no>
Re: How to use Net::FTP - FTP Client class through a Fi <bobx@linuxmail.org>
Re: Memory used by hashes <ddunham@redwood.taos.com>
Re: Memory used by hashes (Anno Siegel)
Re: Memory used by hashes <grazz@nyc.rr.com>
Re: Memory used by hashes <nospam@euro.com>
Re: Memory used by hashes <ddunham@redwood.taos.com>
Re: Perl querystring encoding question <peakpeek@purethought.com>
Re: print to file safley <usenet@tinita.de>
Re: print to file safley <mbudash@sonic.net>
Re: print to file safley <usenet@tinita.de>
Re: Problem using CGI.pm and SSL. <me@privacy.net>
regexp question <mike@luusac.co.uk>
Re: regexp question <mbudash@sonic.net>
Re: Reverse assignment operator <goldbb2@earthlink.net>
Re: Simple regular expression question <me@privacy.net>
Re: Why can not convet binary to decimal using oct? <usenet@tinita.de>
Working with Objects in Perl. (Lax)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Mar 2003 20:54:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: creating an error box
Message-Id: <3E7BC246.BEF3DA74@earthlink.net>
Ben wrote:
>
> Hi,
>
> I have a perl script called by several applications that currently
> logs errors to a log (when one occurs) but does not inform the user
> about the error. What I would like to do is to pop up an error window
> that the user can click "ok" on aside from the logging of the error
> that is currently happening.
>
> Can someone point me to what I would need to use to accomplish this?
On windows, you can do:
use Win32;
Win32::MsgBox("Error message", 0, "Error!");
There's a similar function on Mac, though I forget what it is.
This is a lot lightweight than loading up Tk.
On some versions of *nix, there exist utilities whose sole purpose is to
pop up a window with a message in it. As your local unix guru to tell
if one exists on your machine, and how to invoke it. If there isn't
such a thing, you can either create such a utility, or use Tk from
within perl to do it. (Or WxPerl, or Qt, or ... Go to CPAN and look in
the "User Interfaces" category)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 21 Mar 2003 20:30:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E7BBCBF.322D3344@earthlink.net>
Xavier Noria wrote:
> Michael Carman wrote:
>
> :> * Is length("\n") == 1 true in all platforms?
> :
> : Yes; within Perl \n is \012, regardless of platform.
False -- on Mac "\n" is \015.
It is, however, true that length("\n") == 1, regardless of platform.
> :> * Is (default) $/ eq "\n" true in all platforms?
> :
> : Yes.
>
> OK, so this sentence from perlport:
>
> A common misconception in socket programming is that "\n" eq "\012"
> everywhere.
>
> refers to "\n" *after* the low-level print.
>
> If "\n" eq "\012" is true in all platforms (as strings, no I/O),
It isn't.
> how does the I/O system know the first might need translation but not
> the second?
If a filehandle has not been binmode()d, then any "\n" will, if
necessary, be translated to the platform's newline.
It's not necessary on *nix and Mac. On *nix, perl's \n is equal to
\012, and the system's newline is \012, and on Mac, perl's \n is equal
to \015, and the system's newline is \015.
On windows, perl's \n is equal to \012, and the system's newline is
\015\012 -- on that platform, any \n (or equivilantly, any \012) printed
to a non-binmode()d filehandle is translated by the I/O system to
\015\012.
> Does the underlying data managed by the interpreter has a flag in that
> character that marks it as logical newline?
No -- it's the filehandle which knows (due to having not been
binmode()d) when to translate \n to the logical newline.
Sometimes, I wish that \n wasn't *actually* \012 or \015, but rather
were a special character value in the unicode application-private range,
which would, when printed to a binmode()d filehandle, cause perl to
die(), but would, on non-binmode()d handles, silently produce the
system's logical newline.
>>> * When is "\n" converted to "\015\012" under Windows?
>>
>> During the low-level reads and writes. That is, if you say
>>
>> $line = <FH>;
>>
>> \015\012 will be converted to \012 *before* the string is stored
>> in $line.
>
> Then, why does perlport say chop() will just cut half of the
> end-of-line on DOSish systems in a typical while (<FH>) loop?
If you have called binmode() on the filehandle, then the translation
doesn't occur.
Sockets and pipes normally are automatically binmode()d -- I suppose
that if you start another process with a pipe attached to it's stdout,
and read from the other end of that pipe, the data that you read will
have untranslated newlines.
The same goes for when you create a network socket to something which is
sending you \015\012 terminated data -- the newlines won't be
translated.
The simplest way of dealing with untranslated newlines, is to local()ly
set $/ to "\015\012", and chomp() the lines after reading them.
------
Another consideration, is what is done when $/ contains either the empty
string, or a reference to an integer, or undef. In all three of these
cases, chop does the wrong thing and chomp does the right thing. (The
right thing is to remove *all* trailing newlines in the first case, and
to remove nothing in the other two cases).
> If we got always a \012 at the end of the line chop() should be safe
> in that sense, shouldn't it?
It would, *if* that were the case.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 21 Mar 2003 20:42:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E7BBF76.ED973394@earthlink.net>
Helgi Briem wrote:
>
> On Thu, 20 Mar 2003 18:15:36 +0000 (UTC), Xavier Noria
> <fxn@hashref.com> wrote:
>
> >I am not programming nothing diretly related to that, just
> >trying to understand that corner of Perl well.
>
> But linebreaks have nothing whatsoever to do with Perl
> and everything to do with operating systems and their
> conventions.
Technically true, but what Xavier is trying to learn is *how perl deals
with linebreaks*, not *how operating systems deal with linebreaks*.
> Perl programmers just encounter it
> more often than others because Perl is so easily
> portable across platforms. Coincidentally, in the last
> year or so I have been teaching C++, Java, Python
> and Delphi programmers independendently about the
> CR/LF issue as these languages increasingly move into
> the multi-platform arena. Every programmer who
> ports a program from Windows to Unix or vice versa
> eventually bangs their heads against this problem.
> They are usually clueless about how to solve it.
Every perl programmer who writes his perl programs on Windows *doesn't*
bang his head against the problem, since the proper use of binmode() in
the right places will reduce or eliminate the problem completely.
Every C programmer who writes his C programs on Windows *doesn't* bang
his head against the problem, since proper use of O_BINARY and O_TEXT
(or "b" or "t", for stdio) in the right places will reduce or eliminate
the problem completely.
(He may need to add #define O_BINARY 0, and #define O_TEXT 0, for unix,
but this is a truly trivial change).
I'm sure that C++'s iostreams have a similar facility.
A significantly bigger problem of newline portability is when moving
from Unix to Windows, since unix programmers *don't* binmode() their
filehandles, and *don't* use O_BINARY or O_TEXT, or "b" or "t", since
these aren't needed there -- they have to be *added,* and each addition
requires brainpower to decided whether what's needed.
> For myself, I wish the linefeed were standardised as so
> many things have been standardised lately, but I suppose
> that's a pipedream for now.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 21 Mar 2003 20:04:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How can I....?
Message-Id: <3E7BB6B4.C00F531@earthlink.net>
Cyber Scorpion wrote:
> Cyber Scorpion wrote:
> > Benjamin Goldberg wrote:
[snip]
>>> Convert both strings from ISO8859-5 into perl's native utf8 using
>>> either the 'encoding' pragma, or a ":encoding(ISO8859-5)" perlio
>>> layer, or subroutines from the Encode (or Encode::compat) module,
>>> or Text::IConv.
>>>
>>> Then, you would do as normal:
>>>
>>> if( $sdata =~ /^\Q$rdata\E\z/i )
>>> or:
>>> if( lc($sdata) eq lc($rdata) )
>>> or:
>>> if( uc($sdata) eq uc($rdata) )
>>>
>>> Where are $sdata and $rdata coming from? Literal strings? Files?
>>> A database? (The answer to this question is to know what module
>>> will best suit your needs for conversion).
>>
>> I will look for the 'encoding' pragma in perl help. $sdata and $rdata
>> are coming from .html files (this is a part from a simple search
>> engine). $sdata is part of the search string (single word) , $rdata
>> is single word from .html file. Thanks for your help!
>
> I found very very strange partial solution of my problem: if I just
> encode and then decode to unicode everything goes fine (only with big
> performance penalty):
>
> #$sdata = encode_utf8($sdata);
> #$sdata = decode_utf8($sdata);
>
> #$rdata = encode_utf8($rdata);
> #$rdata = decode_utf8($rdata);
Try instead:
my $sdata_new = decode("ISO8859-5", $sdata, Encode::FB_CROAK);
my $rdata_new = decode("ISO8859-5", $rdata, Encode::FB_CROAK);
The original $[rs]data strings are in Cryllic, the $[rs]data_new strings
are in perl's internal (utf8) encoding and have the UTF8 flag set on
them -- as a result, they will compare in the proper manner.
If you want to output parts of these strings, make sure you re-encode
those parts into cryllic before printing them.
> # Now the code bellow works for cyrillic characters!!!
> if ($sdata =~ /$rdata/i)
> {
> ...
> }
>
> Unfortunately some of the cyrillic strings in the $rdata (from the
> .html files) are totaly unusable (something happened while
> encoding/decoding) and looks like this - "?? ?????? ?? ?? ????????".
That's because you claimed that the original data was utf8, when it was
actually cryllic, and as a result, the data was corrupted. In addition,
your browser is (I assume) expecting cryllic data, and the current
encoding of those strings is perl's internal format, isntead -- you have
print out encode("ISO8859-5", $whatever) instead.
> Please HELP me to resolve this! Thank you...
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 22 Mar 2003 00:55:11 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: How to include data stamps in a script??
Message-Id: <pan.2003.03.21.20.05.18.633956@aursand.no>
On Thu, 20 Mar 2003 09:17:21 -0800, John Smith wrote:
> test1_links_20030320[1].html, when I run the script for the first time.
> When I run the scipt second time on the same day, I need to get another
> file, test1_links_20030320[2].html and so on..
>
> Would you pl. elaborate your explanation (by writing the code)?
I have already given you some code to play with. What part of it didn't
you understand?
--
Tore Aursand
------------------------------
Date: Sat, 22 Mar 2003 01:30:14 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: How to use Net::FTP - FTP Client class through a Firewall
Message-Id: <G0Pea.3324$FN.2448845@news2.news.adelphia.net>
"Joe Kamenar" <joey19020@aol.com> wrote in message
news:fca4c27e.0303211202.1c00aec@posting.google.com...
> Greetings,
>
> Thanks to those who answered my previous question on using the
> net::ftp. I realized that I have to get through our firewall to get to
> the ftp site. I can not find any examples of how to do this.
>
> If I have the following info, how do I construct the $ftp statement to
> create the $ftp object, using the firewall parameters?
>
> FIREWALL INFO:
> HOST=ftp-gateway.xxxx.net
> USERID=fundstn
> PASSWORD=password
>
Could it be possible your firewall is just configured NOT to let ftp
through?
------------------------------
Date: Fri, 21 Mar 2003 23:17:10 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Memory used by hashes
Message-Id: <W3Nea.4325$sM3.246936803@newssvr21.news.prodigy.com>
Fr€d <nospam@euro.com> wrote:
> I am running a simple perl program that sums 5 variables over 100Gb of
> data. I have 5 hashes that use the same 12 character key. There are
> about 4 million keys. Basically the program is:
> while (<INPUT>) {
> $key =substr($_,0,12);
> extract 5 numbers from $_;
> $sum1{$key} ++;
> $sum2{$key} += $val;
> ... (for all 5 sums)
> }
That's not 5 sums, that's 5 * 4 million sums. Yes? Is that what you
expect?
The "extract 5 numbers from $_" isn't perl, and I have no idea what you
intend by that. $val is never initialized, and I can't really guess
what really happens in the ...(for all 5 sums) section.
Could you...
1) show some sample data?
2) show the actual code within that loop?
> Can anyone explain why this is using so much memory? Even given that
> all variables are double precision, I can only come up with about 20% of
> what's being used. I thought all hashes that used the same key were
> stored in one place; this seems to indicate that this isn't the case.
Where did you hear that? I don't know what it would mean anyway. If
you have multiple hashes, then you have to store multiple values, and
that takes space.
Bascially native perl variables are very easy to use, very flexible, but
not very space efficient.
I can guess some alternatives that might work (use one hash instead of
five with array refs or something even more space efficient), but I'm
not convinced I have any idea about what you actually want yet.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: 21 Mar 2003 23:29:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memory used by hashes
Message-Id: <b5g78h$jj2$1@mamenchi.zrz.TU-Berlin.DE>
Fr d <nospam@euro.com> wrote in comp.lang.perl.misc:
> I am running a simple perl program that sums 5 variables over 100Gb of
> data. I have 5 hashes that use the same 12 character key. There are
> about 4 million keys. Basically the program is:
>
> while (<INPUT>) {
> $key =substr($_,0,12);
> extract 5 numbers from $_;
> $sum1{$key} ++;
> $sum2{$key} += $val;
> ... (for all 5 sums)
> }
>
> The job is currently running and is using about 685Mb of memory at about
> 2/3 the way thru the data. 80% of the keys have appeared by now I'd
> expect.
>
> Can anyone explain why this is using so much memory? Even given that
> all variables are double precision, I can only come up with about 20% of
> what's being used. I thought all hashes that used the same key were
> stored in one place; this seems to indicate that this isn't the case.
I'm not much surprised at the overhead you see, it's the Perl way.
The loss doesn't happen in the hash keys (the mechanism you mention
is in place and helps), but in the 20 million scalars you are storing.
A perl scalar takes up much more room than the numeric content.
If you need everything in memory, you could save space by pack()ing
the five numbers for each key into a single string (and store them
in a single hash, though that isn't the main point). That reduces
the number of scalars by 5.
If you don't need everything in memory at once (for instance, if
the purpose of the maneuver is to create another file), and if
the input can be sorted (or happens to be) you can work through
the file line-wise without using much more memory than needed for
a single line. However, sorting those 100 GB may be prohibitive.
Anno
------------------------------
Date: Fri, 21 Mar 2003 23:29:43 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Memory used by hashes
Message-Id: <HfNea.876$LJ2.930466@twister.nyc.rr.com>
Fr€d <nospam@euro.com> wrote:
> I am running a simple perl program that sums 5 variables
> over 100Gb of data. I have 5 hashes that use the same 12
> character key. There are about 4 million keys. Basically
> the program is:
>
> while (<INPUT>) {
> $key =substr($_,0,12);
> extract 5 numbers from $_;
> $sum1{$key} ++;
> $sum2{$key} += $val;
> ... (for all 5 sums)
> }
>
> The job is currently running and is using about 685Mb of
> memory at about 2/3 the way thru the data. 80% of the keys
> have appeared by now I'd expect.
>
> Can anyone explain why this is using so much memory?
> Even given that all variables are double precision [...]
Scalars are bulkier than you think.
On i686-linux 'ints' and 'doubles' take up 28 and 36 bytes.
--
Steve
------------------------------
Date: Fri, 21 Mar 2003 16:29:32 -0800
From: Fr€d <nospam@euro.com>
Subject: Re: Memory used by hashes
Message-Id: <3E7BAE6C.493D@euro.com>
Darren Dunham wrote:
>
> Fr€d <nospam@euro.com> wrote:
> > I am running a simple perl program that sums 5 variables over 100Gb of
> > data. I have 5 hashes that use the same 12 character key. There are
> > about 4 million keys. Basically the program is:
>
> > while (<INPUT>) {
> > $key =substr($_,0,12);
> > extract 5 numbers from $_;
> > $sum1{$key} ++;
> > $sum2{$key} += $val;
> > ... (for all 5 sums)
> > }
>
> That's not 5 sums, that's 5 * 4 million sums. Yes? Is that what you
> expect?
yes
> The "extract 5 numbers from $_" isn't perl, and I have no idea what you
> intend by that. $val is never initialized, and I can't really guess
> what really happens in the ...(for all 5 sums) section.
well, it was more pseudo code; I am summing 5 variable per key
and tried to make the example short
> Could you...
>
> 1) show some sample data?
> 2) show the actual code within that loop?
>
> > Can anyone explain why this is using so much memory? Even given that
> > all variables are double precision, I can only come up with about 20% of
> > what's being used. I thought all hashes that used the same key were
> > stored in one place; this seems to indicate that this isn't the case.
>
> Where did you hear that? I don't know what it would mean anyway. If
> you have multiple hashes, then you have to store multiple values, and
> that takes space.
$ perldoc perltoot
(Arrays as Objects subsection):
A hash representation takes up more memory than an array
|representation because you have to allocate memory for the keys as well
as for the values. However, it really isn't that bad, especially since
as of version 5.004, memory is only allocated once for a given hash
key, no matter how many hashes have that key.
or:
http://www.cs.berkeley.edu/~loretta/perl/nmanual/pod/perltoot/Arays_as_Objects.html
> Bascially native perl variables are very easy to use, very flexible, but
> not very space efficient.
I see that now, thanks
> I can guess some alternatives that might work (use one hash instead of
> five with array refs or something even more space efficient), but I'm
> not convinced I have any idea about what you actually want yet.
Well, I don't have any problems running it, I was just curious about
the memory usage.
thanks
------------------------------
Date: Sat, 22 Mar 2003 01:51:28 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Memory used by hashes
Message-Id: <AkPea.1468$LL7.76330105@newssvr14.news.prodigy.com>
Fr€d <nospam@euro.com> wrote:
> Darren Dunham wrote:
>>
>> Where did you hear that? I don't know what it would mean anyway. If
>> you have multiple hashes, then you have to store multiple values, and
>> that takes space.
> $ perldoc perltoot
> (Arrays as Objects subsection):
> A hash representation takes up more memory than an array
> |representation because you have to allocate memory for the keys as well
> as for the values. However, it really isn't that bad, especially since
> as of version 5.004, memory is only allocated once for a given hash
> key, no matter how many hashes have that key.
Hmm. I didn't really see that. I presume that it means that your keys
are only stored once. But you still have all the 4 million values for
each of the five hashes.
>> I can guess some alternatives that might work (use one hash instead of
>> five with array refs or something even more space efficient), but I'm
>> not convinced I have any idea about what you actually want yet.
> Well, I don't have any problems running it, I was just curious about
> the memory usage.
Reducing the number of scalars will be the main way to improve it.
If you're going to summarize these 5 * 4 million values (perhaps by
summing or averaging), you might want to do it as they're read rather
than storing them all.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Sat, 22 Mar 2003 02:00:38 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Perl querystring encoding question
Message-Id: <vjfn7vg7tvh6qo6al03pq1ieunu8g8evbk@4ax.com>
On Fri, 21 Mar 2003 00:30:30 GMT, in comp.lang.perl.misc, Michael Budash <mbudash@sonic.net> wrote:
>In article <907e039c.0303201234.1de824c4@posting.google.com>,
> rdodd@xltech.net (Robert Dodd) wrote:
>
>> I am trying to pass values in a querystring that come from a a flat
>> file db extracted using Perl (see code below) Can anyone tell me how
>> to encode the variable encoding querystring variables $job_title?
>> right now it get truncated because it contains a / the code is below
>
>[snip unnecessary code example]
>
>> application.shtml?email=$contact_email&state=$state&position=$job_title
>
>[snip rest of unnecessary code example]
>
>if you're using the CGI perl module:
>
>my $href = 'application.shtml?email=' .
> CGI::escape($contact_email) .
> '&state=' .
> CGI::escape($state) .
> '&position=' .
> CGI::escape($job_title);
'&' is not valid HTML here
CGI.pm has a query_string() method, which calls its escape()
method, and then constructs the query string ...
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;
my ($contact_email, $state, $job_title)
= ('rdodd@xltech.net', 'Florida', 'Analyst/Programmer');
my $query = new CGI ({'email'=>$contact_email,
'state'=>$state,
'position'=>$job_title});
print 'application.shtml?', $query->query_string, "\n";
------------------------------
Date: 21 Mar 2003 23:05:37 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: print to file safley
Message-Id: <tinhc4g6e$3cc$tina@news01.tinita.de>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> Also sprach Tina Mueller:
>> sure, but the OP is reading the file, closing it and opening it again.
>> even if you do both reading and writing with flock(), in that
>> time in between the two open()/close() there is *no* lock at all.
> Well, true, but there is no I/O happening in this program either in
> these moments. After releasing the lock for a few moments, another
> process could aquire a fresh lock. So when the program opens the file
> again it wont get the lock so it will block.
but "these moments" are relative:
00:01am tina@lux:tests 614> cat board.pl
#!/usr/bin/perl -w
use strict;
use Fcntl qw(:flock);
$|=1;
open FH, "<board" or die $!;
flock FH, LOCK_SH;
my @a = <FH>;
close FH;
select undef,undef,undef,0.001;
my $new = "$ARGV[0]\n";
push @a, $new;
open FH, ">board" or die $!;
flock FH, LOCK_EX;
print FH @a;
close FH;
print "PID $$\n";
00:01am tina@lux:tests 615> cat board_call.pl
#!/usr/bin/perl -w
$|=1;
system "perl board.pl D &";
system "perl board.pl E &";
print "end\n";
00:02am tina@lux:tests 634> cat board
A
B
C
00:03am tina@lux:tests 635> perl board_call.pl
end
00:03am tina@lux:tests 636> PID 4326
PID 4328
00:03am tina@lux:tests 636> cat board
A
B
C
E
so entry D got lost...
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace
------------------------------
Date: Sat, 22 Mar 2003 00:37:24 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: print to file safley
Message-Id: <mbudash-FE0488.16372321032003@typhoon.sonic.net>
In article <b5g3hi$28cnml$2@ID-24002.news.dfncis.de>,
Tina Mueller <usenet@tinita.de> wrote:
> Blnukem <blnukem@hotmail.com> wrote:
>
> > open (REPLY, "<data/msgboard/$FORM{'forum'}/$FORM{'file'}.dat");
> > my @new_post = <REPLY> ;
> > close(REPLY);
>
> [...]
> > push( @new_post, $posted);
>
> > open (REPLY, ">data/msgboard/$FORM{'forum'}/$FORM{'file'}.dat");
> > flock(REPLY, 2);
> > print REPLY @new_post;
> > flock(REPLY, 8);
> > close(REPLY);
>
> why don't you just open the file for appending?
> #!perl -wT
> use strict;
> use Fcntl qw(:flock);
> # ...
> # untaint $FORM{'forum'} and $FORM{'file'}
> # see
> # perldoc perlsec
> open REPLY, ">>data/msgboard/$FORM{'forum'}/$FORM{'file'}.dat") or die $!;
> flock REPLY, LOCK_EX;
> print REPLY $posted;
> close REPLY;
>
> hth, tina
yes - this is the correct method, tina. however, you should still seek
to end-of-file just in case the file was appended to after the open, but
before the flock (hey, it's not impossible):
#!perl -wT
use strict;
use Fcntl qw(:flock);
# ...
# untaint $FORM{'forum'} and $FORM{'file'}
# see
# perldoc perlsec
open REPLY, ">>data/msgboard/$FORM{'forum'}/$FORM{'file'}.dat") or die
$!;
flock REPLY, LOCK_EX;
seek REPLY, 0, 2;
print REPLY $posted;
close REPLY;
hth-
------------------------------
Date: 22 Mar 2003 01:08:05 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: print to file safley
Message-Id: <tinhc4luk$4lx$tina@news01.tinita.de>
Michael Budash <mbudash@sonic.net> wrote:
> In article <b5g3hi$28cnml$2@ID-24002.news.dfncis.de>,
> Tina Mueller <usenet@tinita.de> wrote:
>> open REPLY, ">>data/msgboard/$FORM{'forum'}/$FORM{'file'}.dat") or die $!;
>> flock REPLY, LOCK_EX;
>> print REPLY $posted;
>> close REPLY;
> yes - this is the correct method, tina. however, you should still seek
> to end-of-file just in case the file was appended to after the open, but
> before the flock (hey, it's not impossible):
i actually tested it by doing a sleep() between open() and
flock(), and by starting 2 processes at the same time.
it always was printed correctly, so i guessed that open
for appending does automagically seek to the end at the
first print. but now i'm not sure. does anybody know if/where
this is documented?
after the open() tell(FH) returns the same for both processes.
even after flock() it returns the same.
after the print then it returns different (and correct) values
for each process.
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace
------------------------------
Date: Sat, 22 Mar 2003 10:37:22 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Problem using CGI.pm and SSL.
Message-Id: <b5g7nk$29dh39$1@ID-172104.news.dfncis.de>
"Hemant Shah" <shah@typhoon.xnet.com> wrote in message
news:b5fbth$nem$1@flood.xnet.com...
> While stranded on information super highway Hemant Shah wrote:
> :)
> :)Folks,
> :)
> :) We have apache server installed with SSL support. When I use
> :) https://www.mysite.com, it brings up standard apache intro page. So
SSL
> :) seems to work.
> :)
> :) I wrote a web page using perl CGI.pm and can display it via
> :) http://www.mysite.com/myscript.pl. When I run the same script using
> :) https://www.mysite.com/myscript.pl I get server error displayed in the
> :) browser. When I looked at the apache error_log, it following message
> :)
> :) Premature end of script headers: /full/path/to/myscript.pl
> :)
> :) What am I missing?
> :)
> :)
> :) I have print $q->header; in my script.
>
> The next question may not be for this news group, but when I searched
> google groups for "Premature end of script headers", most of the hits
came
> from this news group.
>
> O.K. I created a simple perl script as follows:
>
> #!/usr/local/bin/perl -w
>
> print "Content-Type: text/html
>
>
> <HTML>
> <HEAD>
> </HEAD>
> <BODY>
> <H1>This is a test <H1>
> </BODY>
> </HTML>
>
> ";
> exit(0);
Try
#!/usr/local/bin/perl -w
$|=1;
print <<EOF;
Content-Type: text/html
<HTML>
<HEAD>
</HEAD>
<BODY>
<H1>This is a test <H1>
</BODY>
</HTML>
EOF
------------------------------
Date: Sat, 22 Mar 2003 01:16:27 -0000
From: "Mike" <mike@luusac.co.uk>
Subject: regexp question
Message-Id: <oUOea.405$N73.4421@newsfep4-glfd.server.ntli.net>
Hi,
I am trying to read in a file line by line and then print / assign to an
array the line following one matched by a regexp, ie
if I have
Line 1:<start>Hello World#
Line 2:This is what I want
Line 3: blah
Line 4: blah blah
Line 5:<stop>
Line 6:<start>Hello Again#
Line 7: I want this too !
Line 8: blah
Line 9: blah blah
Line 10:<stop>
etc
So that I know the content I want will always be preceded by a line which
ends in a '#'. Is it possible to do it this way, or will I have to read in
/ slurp the whole file and then parse it ?
thanks
Mike
------------------------------
Date: Sat, 22 Mar 2003 01:33:12 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: regexp question
Message-Id: <mbudash-959300.17331121032003@typhoon.sonic.net>
In article <oUOea.405$N73.4421@newsfep4-glfd.server.ntli.net>,
"Mike" <mike@luusac.co.uk> wrote:
> Hi,
>
> I am trying to read in a file line by line and then print / assign to an
> array the line following one matched by a regexp, ie
>
> if I have
>
> Line 1:<start>Hello World#
> Line 2:This is what I want
> Line 3: blah
> Line 4: blah blah
> Line 5:<stop>
> Line 6:<start>Hello Again#
> Line 7: I want this too !
> Line 8: blah
> Line 9: blah blah
> Line 10:<stop>
>
> etc
>
> So that I know the content I want will always be preceded by a line which
> ends in a '#'. Is it possible to do it this way, or will I have to read in
> / slurp the whole file and then parse it ?
>
> thanks
>
> Mike
>
>
sure -
while (<FILE>) {
if (/#$/) {
<FILE>;
print;
}
}
hth-
------------------------------
Date: Fri, 21 Mar 2003 19:50:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Reverse assignment operator
Message-Id: <3E7BB364.32AEC43C@earthlink.net>
Tore Linde Gustavsen wrote:
>
> My last post is a prime example of bad wording: Here's what I meant to
> say:
>
> To Tassilo and Bernard: Thanks again for good, instructive replies.
>
> Bernard talks about perl6, and I am of course looking forward to when
> it will be released.
>
> I know it is very uncertain, but the date of release is still years
> ahead in time?
Perl6 is being designed to run on the Parrot Virtual Machine as it's
primary platform (similarly to how Java uses the JVM as it's main
platform).
Parrot is coming along quite well, has frequent improvements, and runs
fairly quickly. It's not *fully* featured yet, most notably lacking
namespaces, an object system, exceptions, and threads. It does have an
IO system, PIO, based on perlio, which it uses instead of stdio; it also
has an optomizer, and just-in-time compilation.
There is an incomplete Perl6 to Parrot assembler compiler -- most of the
recent changes to it were back in September 2002, with some some changes
in December 2002. (There're a few files with later timestamps, but they
are mostly pieces of example perl6 code.)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 22 Mar 2003 10:51:48 +1100
From: "Peter Sundstrom" <me@privacy.net>
Subject: Re: Simple regular expression question
Message-Id: <b5g8im$2825r5$1@ID-172104.news.dfncis.de>
"Stephane Gregoire" <stephanegregoire@hotmail.com> wrote in message
news:9ed209ed.0303210602.1e2d6fd7@posting.google.com...
> I need to build a regular expression that matches the following
> sentences:
>
> This is a sentence with some words
> -or-
> This is a sentence containing some words
>
>
> I want to be able to tell the regexp that you can choose the word
> "with" or "containing" in the middle of the sentence.
>
> I know I can use the OR operator(|) and put it between two regexp
> like:
>
> /^This is a sentence with some words/|/^This is a sentence containing
> some words/
>
> but is there a way to shorten the regex? Something like
> /^This is a sentence (containing|with) some words/ ?
Congratulations. You've earned an entry in the Perl SAQ
http://www.ginini.com/perlsaq.html
------------------------------
Date: 22 Mar 2003 00:13:31 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Why can not convet binary to decimal using oct?
Message-Id: <tinhc4jbp$4cw$tina@news01.tinita.de>
Chris Lowth <please@no.spam> wrote:
>>> my @list= ("0b0011", "0x041");
>>> foreach (@list){
>>> print oct($_),"\n";
>>> }
>>> The result is:
>>> 0
>>> 65
> Is this a version issue? What perl version are you using, and on what
> platform (not that the latter point should make any difference)?
i get the same with perl5.00404 and perl5.00405.
seems to be supported since 5.6.1:
http://www.perldoc.com/perl5.6.1/pod/perldelta.html#Binary-numbers-supported
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace
------------------------------
Date: 21 Mar 2003 16:51:46 -0800
From: lax_reddy@hotmail.com (Lax)
Subject: Working with Objects in Perl.
Message-Id: <ecd05021.0303211651.52baad71@posting.google.com>
I'm a Perl newbie working on object-oriented Perl.
Could somebody please help with this.
I'm trying to set a property of an object.
I'm able to get the value of an object's property, but am unable to
set it.
I get the errors : "Can't modify non-lvalue subroutine call at
<line-number>"
============================================
use Win32::OLE;
$getMSI = $ARGV[0] ;
Win32::OLE::CreateObject("WindowsInstaller.Installer",$ins) || die
"Cant create object : $! !!\n" ;
$database = $ins->OpenDatabase($getMSI, 0) || die "Cant open
connection : $!\n" ;
$summaryInfo = $database->SummaryInformation(17) ;
$getProperty = $summaryInfo->Property(4) ;
printf "Property: $getProperty\n" ;
# I need to set $summaryInfo's Property(4) to a new value here.
$getDB->Persist() ;
=============================================
"SummaryInformation" is a property of "database" object.
"$summaryInfo" is the "SummaryInfo" object.
I access the "Property" property of this($summaryInfo) object and am
able to get its value.
But am unable to set its value.
Thanks in advance,
Lax
------------------------------
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 4742
***************************************