[13847] in Perl-Users-Digest
Perl-Users Digest, Issue: 1257 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 2 18:05:37 1999
Date: Tue, 2 Nov 1999 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)
Message-Id: <941583916-v9-i1257@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 2 Nov 1999 Volume: 9 Number: 1257
Today's topics:
* Robust NEWS Application needed ASAP *** <mknutson@baselogic.com>
Re: -w (David H. Adler)
An Observation Re: Statistics for comp.lang.perl.misc <gellyfish@gellyfish.com>
Re: Anyone know of a perl script that ... <cassell@mail.cor.epa.gov>
Re: Book suggestions <cassell@mail.cor.epa.gov>
Re: C++ and embedded perl <cassell@mail.cor.epa.gov>
Re: Card shuffling <lr@hpl.hp.com>
Re: CGI Programming in C/C++ HELP! <jeffp@crusoe.net>
Re: comparing text with words <jeffp@crusoe.net>
Counting multiple macthing vars in an array <hawkwynd@my-deja.com>
Re: Counting multiple macthing vars in an array (Kragen Sitaker)
Re: Counting multiple macthing vars in an array <lr@hpl.hp.com>
Re: dirty textfiles <lr@hpl.hp.com>
Re: dirty textfiles (Craig Berry)
Re: Don't we have POINTERS on Perl? (Jan Dubois)
Re: Extract string ? <cassell@mail.cor.epa.gov>
Re: Extract string ? <cassell@mail.cor.epa.gov>
Re: Extract string ? <cassell@mail.cor.epa.gov>
Re: FAQ 2.14: What mailing lists are there for perl? (David H. Adler)
Re: Formatting a Date Properly (Kragen Sitaker)
Re: Help!!! Need Net::Ping to work ASAP! <cassell@mail.cor.epa.gov>
Re: Hiding Perl Scripts? <rootbeer@redcat.com>
Re: Hiding Perl Scripts? <cassell@mail.cor.epa.gov>
Re: How do I create a library file of subroutines? <rootbeer@redcat.com>
HTTP::Date (Bill Moseley)
Re: HTTP::Date <gisle@aas.no>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 02 Nov 1999 13:44:35 +0000
From: Mick Knutson <mknutson@baselogic.com>
Subject: * Robust NEWS Application needed ASAP ***
Message-Id: <381EEAC3.76078185@baselogic.com>
I need a robust way to manage news on my web site.
I have multiple columnists, and want to manage the news via a web page.
--
Thanks
Mick Knutson
BLiNC Magazine
http://www.baselogic.com
------------------------------
Date: 2 Nov 1999 16:07:50 -0500
From: dha@panix.com (David H. Adler)
Subject: Re: -w
Message-Id: <slrn81ukl5.7mh.dha@panix.com>
On Mon, 01 Nov 1999 17:22:34 -0800, David Cassell
<cassell@mail.cor.epa.gov> wrote:
>Uri Guttman wrote:
>>
>> >>>>> "DC" == David Cassell <cassell@mail.cor.epa.gov> writes:
>> DC> Jeff Pinyan wrote:
>> DC> [snip]
>> >> On a totally unrelated note, November 9th shall be my undoing. For I
>> >> shall be 18 years of age. Look out.
>>
>> DC> Mazel tov. We eagerly await your posts after Nov 9. Probably
>> DC> lots of drunken posts after midnight, and then lots of really
>> DC> surly hangover-laden posts on the subsequent mornings. Should
>> DC> liven things up considerably. :-)
>> but min drinking age is 21 all over
>> the .us. but now japhy can vote and create all sorts of nasty perl
>> voting scripts to elect his favorite politician.
>
>Nah, I'm just so old I got to drink legally at age 18.
*I* was lucky enough to be of legal drinking age at 18... for about 3
months. Then they changed the law on me. Scum. :-/
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You're quite free to convert your strings to byte arrays and do the
entire pattern tree by hand in pure logic code if you'd like. By the
time you finish most of the rest of us will be doing contract work on
Mars." - Zenin on comp.lang.perl.misc
------------------------------
Date: 1 Nov 1999 21:36:58 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: An Observation Re: Statistics for comp.lang.perl.misc
Message-Id: <7vl15q$4fo$1@gellyfish.btinternet.com>
On 1 Nov 1999 15:08:41 GMT Greg Bacon wrote:
> Following is a summary of articles spanning a 7 day period,
<etc>
An observation from which I draw no particular inference - but none of
the top 10 posters use spam trapped adresses however the list of top
*new* posters seems to have a number ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Tue, 02 Nov 1999 14:28:04 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Anyone know of a perl script that ...
Message-Id: <381F6574.E9770AF6@mail.cor.epa.gov>
Dalton Hunter wrote:
>
> ... will send an email to someone when an IP addresses is accessing a site X
> amount of times a minute so that one can look into it and decide if they
> want to add the IP to their .htaccess's deny list? Thanks!
I don't know of one, but if there is one you ought to be able to
find it on the web by searching for reasonable keywords.
Alternatively, you might consider writing it yourself. Just
remember the issues involved, including forged IP addresses
and proxies. Also, consider the range of ports you plan to
protect...
Good luck, and when you get some code written you may want to
come back here and ask some specific questions about coding
and networking.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 02 Nov 1999 14:47:29 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Book suggestions
Message-Id: <381F6A01.7E5ED25A@mail.cor.epa.gov>
Uri Guttman wrote:
>
> >>>>> "A" == Abigail <abigail@delanet.com> writes:
>
> A> Joel Berger (joel_berger@manulife.com) wrote on MMCCLIII September
> A> MCMXCIII in <URL:news:2mlT3.386$Ao3.125@198.235.216.4>:
> A> ,, Suggestions for a good book for a newbie?
>
> A> Winnie-the-Pooh.
>
> more accurate than perl for dummies and not as condescending to the
> reader. good choice!
Actually, I just received _free_ from Manning a copy of
Andrew Johnson's book "Elements of Programming with Perl".
It looks like it may be a very good choice for a true beginner
who has never programmed before. It doesn't attempt to be
an encyclopedic presentation, but it does seem to carefully
cover most of the key topics. I'll give you a more
definite statement after I have a chance to scan it.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 02 Nov 1999 15:02:06 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: C++ and embedded perl
Message-Id: <381F6D6E.6900D23A@mail.cor.epa.gov>
David Rankin wrote:
>
> The only language that I am aware of that will interface with C or C++ is
> assembly via the asm keyword. The way it works is to invoke the assembly
> compliler like this:
[big snip]
Umm David, I guess this means that you have not read the
perlxs, perlembed, and perlxstut pages in the documentation.
Perl is designed to interface cleanly with C [and C++ too].
And, when you post, please follow Usenet etiquette and place your
reply *after* the poster's words. It makes threads feasible,
and it makes Usenet work better. It will also keep pedants
here from annoying you [other than this paragrpah, of course :-].
TIA,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 2 Nov 1999 12:06:59 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Card shuffling
Message-Id: <MPG.1288e43c7a0c5cfb98a191@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <slrn81u5d1.9ap.bet@localhost.localdomain> on Tue, 02 Nov
1999 16:47:31 GMT, Bennett Todd <bet@network.rahul.net> says...
> 1999-11-01-23:00:06 Larry Rosler:
> >1999-11-01-21:31:49 Bennett Todd:
> >> for my $i (0..$#deck-1){@deck[$i, $_]=@deck[$_, $i] for $i+rand($#deck-$i+1)}
> >>
> >> That shuffles an N-card deck using N-1 calls to rand() and swaps. If the
> >> performance edge of doing an in-place swapping shuffle isn't important, it
> >> might be more understandable as
> >>
> >> @shuffled = ();
> >> push @shuffled, splice(@deck, rand(@deck), 1) while @deck;
> >
> >What is wrong with the discussion in perlfaq4: "How do I shuffle an
> >array randomly?" It gives both of these methods (improving on the first
> >one slightly), and describes the latter one as 'bad'.
>
> For the first one, the only slight improvement I see is that it adds a
> check to optimize out the case of a null swap. I've no idea whether the
> test costs enough to pay for itself. So of course now I have to time
> 'em.....
Yes, that's the slight improvement I meant. Your benchmark seems to
indicate that testing for redundant swaps instead of just doing them is
a timesaver.
> Meanwhile, the FAQ may call the latter one "bad", but I think it
> wins on understandability, and that's sometimes worth sacrificing a little
> performance for. So on to the benchmark. Here's the code I used:
This is the quote from the FAQ:
"This is bad because splice is already O(N), and since you do it N
times, you just invented a quadratic algorithm; that is, O(N**2). This
does not scale, although Perl is so efficient that you probably won't
notice this until you have rather largish arrays."
I guess that 52 cards isn't a 'rather largish' array.
...
> I'm also kinda surprised at the amount of difference between my formulation
> of Fisher-Yates and the FAQ's; as best I can tell, there's an extra test in
> the FAQ's that will save a small fraction of the swaps, so it might be a win
> or a lose (which costs more, the test or the swaps that it saves); and the
> FAQ Fisher Yates counts in the opposite direction, back from the end where
> I count forwards. I can't see either of those explaining the factor of 1.77
> difference.
I'm surprised also.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 2 Nov 1999 16:30:18 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: CGI Programming in C/C++ HELP!
Message-Id: <Pine.GSO.4.10.9911021627360.12955-100000@crusoe.crusoe.net>
> "CGI Programming on the World Wide Web"
"Flying in the Air"
"Swimming in Water"
"Throwing Projectiles"
"Swallowing with Your Throat"
Where else does one apply CGI? :)
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: Tue, 2 Nov 1999 16:18:13 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: comparing text with words
Message-Id: <Pine.GSO.4.10.9911021614220.12955-100000@crusoe.crusoe.net>
[posted & mailed]
> ## tr/abc\/ABC\\/
> ##
> ## changes a->A, b->B, c->C, /->\
>
> I think you meant:
>
> tr/abc\//ABC\\/;
Err, right. Typo on my part. (That's 1000 lashes tonight.)
> So, how can I get a tab if I use 't' as my tr/// delimiter?
> Apprently, I can't :(
That's because "t" is then given a three-fold possibility:
t tr/// delimiter
\t escaped delimiter
\t tab character
But \t is already a LITERAL t. And \\t is a literal backslash.
When you use a character that doesn't have a special meaning when preceded
by a \, you're safe:
tr %$@\%%456%
So the moral of the story is, if you want a \X, don't use X as the
delimiter.
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: Tue, 02 Nov 1999 21:02:46 GMT
From: Hawkwynd <hawkwynd@my-deja.com>
Subject: Counting multiple macthing vars in an array
Message-Id: <7vnjhk$hea$1@nnrp1.deja.com>
Below is a routine that I am struggling with, here's the pseudocode:
Read each line of text into an array;
Assign each value within that line to a variable;
For each $opid found, compare that value to those in the list, and
}
count instances found for that $opid;
if $opid has not been printed, print it and it's counter
}
---------------------- End psudeocode -----------------
I have a list of 4 digit operator id's, unknown number, in an unknown
amount. I need to create a list of the id's, and count how many times
each operator id shows up in the list. For each unique id, i need to
show a report for that many hits on each id.
As I stated, I do not know the operator ID's, but can create a list of
them as shown below. The number of ID's varies, as does the ID's.
So, with that, I need to be able to print a report, that shows all
OPID's, and how many times each OPID shows up in that entire list.
However, I only need to show the OPID once, with it's corresponding hit
count.
Someone have some suggestions?
Here's the code I've got so far...
(open (INF, "$file"))||die("Can't open $file"); # open the file for
reading
@ary=<INF>;
close(INF);
# Remove quotes and dashes from the array
my @foo = map {join "",(split '"|-')} grep {!/^\s*$/} @ary;
foreach (@foo){
# assign each element to a variable
@line = ($amt,$vendor,$callref,$opid,$accnum,$date,$salesrep,$salesrep2)
=(split /,/,$_);
# create @opslist of OPID's
push @opslist, $opid;
}
# count the OPIDs, how many of each?
foreach $item(@opslist){
$count = grep {$_ eq $item} @opslist;
print "$item $count \n";
}
This works, but shows duplicates of the OPIDs and their count.. How can
I NOT show the duplicates, but have the correct count?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 02 Nov 1999 22:36:55 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Counting multiple macthing vars in an array
Message-Id: <bIJT3.22465$23.1153666@typ11.nn.bcandid.com>
In article <7vnjhk$hea$1@nnrp1.deja.com>,
Hawkwynd <hawkwynd@my-deja.com> wrote:
>Read each line of text into an array;
>Assign each value within that line to a variable;
>
>For each $opid found, compare that value to those in the list, and
>}
> count instances found for that $opid;
>
> if $opid has not been printed, print it and it's counter
> }
you mean:
while (read a line of text) {
(a bunch of vars) = split;
for each var {
if it's an opid, $count{that var}++;
}
}
for each opid, print $count{that opid};
Is that what you meant?
>(open (INF, "$file"))||die("Can't open $file"); # open the file for
>reading
>
>@ary=<INF>;
>close(INF);
>
># Remove quotes and dashes from the array
> my @foo = map {join "",(split '"|-')} grep {!/^\s*$/} @ary;
tr might be easier than join(split).
> foreach (@foo){
>
># assign each element to a variable
>@line = ($amt,$vendor,$callref,$opid,$accnum,$date,$salesrep,$salesrep2)
>=(split /,/,$_);
Oh, $opid is the fourth field of the line?
># create @opslist of OPID's
> push @opslist, $opid;
>
> }
># count the OPIDs, how many of each?
> foreach $item(@opslist){
> $count = grep {$_ eq $item} @opslist;
> print "$item $count \n";
You're printing this out once for each input line? Is that what you mean to do?
>
> }
>
>This works, but shows duplicates of the OPIDs and their count.. How can
>I NOT show the duplicates, but have the correct count?
for (@foo) { $count{(split /,/)[3]}++ }
print map { "$_ $count{$_}\n" } sort keys %count;
You can of course expand the loop a bit; you could just as well do the
long drawn-out ($x,$y,$z) = split /,/ thing you're doing above, and
then say $count{$opid}++ instead of the above ugly thing I wrote
above. Might be a good idea if you're doing something more than just
counting opids with the data, or if this is not just a five-minute hack.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Tue, 2 Nov 1999 14:56:53 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Counting multiple macthing vars in an array
Message-Id: <MPG.12890c14c9f12d6e98a192@nntp.hpl.hp.com>
In article <7vnjhk$hea$1@nnrp1.deja.com> on Tue, 02 Nov 1999 21:02:46
GMT, Hawkwynd <hawkwynd@my-deja.com> says...
> Below is a routine that I am struggling with, here's the pseudocode:
<SNIP> of O(N ** 2) algorithm.
...
> I have a list of 4 digit operator id's, unknown number, in an unknown
> amount. I need to create a list of the id's, and count how many times
> each operator id shows up in the list. For each unique id, i need to
> show a report for that many hits on each id.
>
> As I stated, I do not know the operator ID's, but can create a list of
> them as shown below. The number of ID's varies, as does the ID's.
> So, with that, I need to be able to print a report, that shows all
> OPID's, and how many times each OPID shows up in that entire list.
>
> However, I only need to show the OPID once, with it's corresponding hit
> count.
>
> Someone have some suggestions?
Use a hash.
my %opids;
> (open (INF, "$file"))||die("Can't open $file"); # open the file for
> reading
Include $! in the error message.
> @ary=<INF>;
> close(INF);
Don't read in the entire file when you can process it one line at a
time.
> # Remove quotes and dashes from the array
> my @foo = map {join "",(split '"|-')} grep {!/^\s*$/} @ary;
>
> foreach (@foo){
while (<INF>) { # Process one line at a time.
next unless /\S/; # Ignore blank lines.
s/"\|-//g; # Strip garbage (your code above).
> # assign each element to a variable
> @line = ($amt,$vendor,$callref,$opid,$accnum,$date,$salesrep,$salesrep2)
> =(split /,/,$_);
my $opid = (split /,/)[3]; # All you want is the fourth field.
> # create @opslist of OPID's
> push @opslist, $opid;
++$opids{$opid}; # Increase its count in the hash.
# Or you can just put the split into the hash key directly.
> }
> # count the OPIDs, how many of each?
> foreach $item(@opslist){
> $count = grep {$_ eq $item} @opslist;
> print "$item $count \n";
>
> }
print map "$_ $opids{$_}\n" => sort keys %opids;
This sort assumes they are all four digits, as you stated. If not, use
a numeric sort.
> This works, but shows duplicates of the OPIDs and their count.. How can
> I NOT show the duplicates, but have the correct count?
Use a hash.
The above suggestions arn't tested, for lack of a useful data file. But
you'll be able to work from them.
Oh, in case I forgot to tell you:
Use a hash.
This is a paradigmatic example of what they are good for!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 2 Nov 1999 12:06:28 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: dirty textfiles
Message-Id: <MPG.1288e422afce7f1998a190@nntp.hpl.hp.com>
In article <7vnero$be1$1@cubacola.tninet.se> on Tue, 2 Nov 1999 20:46:00
+0100, danfan <nfy339g@tninet.se> says...
> I want to write a little program that reads a textfile
> and replaces dirty bytes with space, including 0x1A = eof
>
> This means I can't use ordinary functions as 0x1A triggers an eof
> condition.
>
> Any suggestions?
perdoc -f binmode
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 02 Nov 1999 21:33:11 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: dirty textfiles
Message-Id: <s1um4nie24263@corp.supernews.com>
danfan (nfy339g@tninet.se) wrote:
: I want to write a little program that reads a textfile
: and replaces dirty bytes with space, including 0x1A = eof
#!/usr/bin/perl -w
# undirty - replace unwelcome characters with spaces.
# Reads from argument file, writes stdout.
# Craig Berry (19991102)
use strict;
die "Useage: undirty _file_ >_outfile_\n" unless @ARGV == 1;
my $filename = shift;
open DIRTY, "< $filename" or die "Can't open $filename: $!\n";
binmode DIRTY;
my $text = do { local $/; <DIRTY>; };
close DIRTY or die "Can't close $filename: $!\n";
# Note: I've made the following transform upper-case letters A, B, and
# C to spaces, along with \x1A, just so it will be easier to demonstrate
# that it's working. Change the left side of the tr/// to meet your
# needs.
$text =~ tr/\x1a\x41\x42\x43/ /;
# The following assumes that the resulting text will be 'clean'
# enough to be handled via the non-binmode STDOUT.
print $text;
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "They do not preach that their God will rouse them
a little before the nuts work loose." - Kipling
------------------------------
Date: Tue, 02 Nov 1999 21:44:29 +0100
From: jand@activestate.com (Jan Dubois)
Subject: Re: Don't we have POINTERS on Perl?
Message-Id: <38264aea.9584511@news3.ibm.net>
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <s1s3999pqof22@corp.supernews.com> on Mon, 01 Nov 1999
>21:59:05 GMT, Craig Berry <cberry@cinenet.net> says...
>> Landim (landim2NOlaSPAM@brhs.com.br.invalid) wrote:
>> : I want to know if we have or not pointers on perl, and
>> : if we have, how to declarate? To manipulate?
>>
[snip]
>To answer 'To manipulate?' further:
>
>You can create a reference, assign a reference, or dereference a
>reference. You can convert a reference to a string, but you cannot
>convert a string to a reference. So you cannot do the arbitrary pointer
>manipulation that is so powerful and so dangerous in C.
Well, actually you can. I've attached below a message I send a few months ago
to the Perl-Win32-Users mailing list to demonstrate that it is unwieldy, but
possible. (I've only quoted the header to make cut&paste easier).
-Jan
PS: The code only works on machines using 4 byte ints and 8 byte doubles.
|To: "Perl-Win32-Users Mailing List" <perl-win32-users@lyris.activestate.com>
|Subject: Perl Pointer Arithmetic (was: perl.exe)
|From: jan.dubois@ibm.net (Jan Dubois)
|Date: Tue, 13 Jul 1999 20:26:28 +0200
[...]
So let's assume you want to find out more about how Perl stores variables
internally. You can get a nice description of the data structures from
Gisle's work: http://home.sol.no/~aas/perl/guts/ but how does it look in
action? You should of course use the Devel::Peek module, but that one works
only with a DEBUGGING Perl. Here is a *very* simplified version in Perl:
#-----------------------------------------------------------------------------
use strict;
sub iv {
printf " IV=%d\n", unpack("I", unpack("P4", pack("I", shift()+12)));
}
sub nv {
printf " NV=%g\n", unpack("d", unpack("P8", pack("I", shift()+16)));
}
sub pv {
my ($pv,$cur,$len) = unpack("III", unpack("P12", pack("I", shift)));
printf " PV=%s\n", unpack("P$cur", pack("I",$pv));
printf " CUR=%d\n", $cur;
printf " LEN=%d\n", $len;
}
my %dump;
$dump{IV} = sub { iv(shift) };
$dump{NV} = sub { nv(shift) };
$dump{PVIV} = sub { my $any=shift; pv($any); iv($any) };
$dump{PVNV} = sub { my $any=shift; pv($any); iv($any); nv($any) };
sub Dump (\$) {
my ($any,$refcnt,$flags) = unpack("III", unpack("P12", pack("I", shift)));
my $type = (qw(NULL IV NV RV PV PVIV PVNV))[$flags & 0xff];
my @flags;
push @flags, "IOK" if $flags & 0x00010000;
push @flags, "NOK" if $flags & 0x00020000;
push @flags, "POK" if $flags & 0x00040000;
push @flags, "ROK" if $flags & 0x00080000;
printf "$type=0x%08x\n", $any;
printf " FLAGS=%s\n", join(',', @flags);
printf " REFCNT=%d\n", $refcnt;
&{$dump{$type}}($any) if exists $dump{$type};
print "\n";
}
my $a = 42;
Dump $a;
$a = "The quick brown fox jumps over the lazy dog";
Dump $a;
$a = 3.141592;
my $b = \$a;
Dump $a;
$b = "$a";
Dump $a;
#-----------------------------------------------------------------------------
Please refer to the web site mentioned above for a description of SVs etc.
I'll just add a little commentary to the output of the program:
# my $a = 42;
# $a is now just an IV, with integer value, IOK is set:
IV=0x00cb79e4
FLAGS=IOK
REFCNT=2
IV=42
# $a = "The quick brown fox jumps over the lazy dog";
# A string value doesn't fit into an IV, so Perl upgrades it to a PVIV. You
# can see that the address of the SV has changed. The flags now say that
# only the string value is valid (POK), but the integer value is still cached.
PVIV=0x00cd18c0
FLAGS=POK
REFCNT=2
PV=The quick brown fox jumps over the lazy dog
CUR=43
LEN=44
IV=42
# $a = 3.141592;
# Now $a must hold a double. There is no space for a double in a PVIV, so
# the scalar is upgraded again to an PVNV, which can hold an IV, NV and PV
# simultaneously. Only the NV is valid now (NOK).
# my $b = \$a;
# We'll add another reference to $a. This does increment the reference count.
PVNV=0x00cd1cb0
FLAGS=NOK
REFCNT=3
PV=The quick brown fox jumps over the lazy dog
CUR=43
LEN=44
IV=42
NV=3.14159
# $b = "$a";
# This uses $a in a "string" context. Perl will cache the string
# representation. $a is already a PVNV, so it doesn't have to be upgraded
# anymore: the address doesn't change. The old string buffer is reused;
# the allocated length is still 44, but only 8 bytes are used. Both the
# PV and the NV are valid now (POK,NOK). And assigning the string value
# to $b did destroy the reference to $a, so the refcount drops by 1:
PVNV=0x00cd1cb0
FLAGS=NOK,POK
REFCNT=2
PV=3.141592
CUR=8
LEN=44
IV=42
NV=3.14159
I still wouldn't recommend to use the pack/unpack tricks unless absolutely
necessary. But it's nice to know that you *can* get at the bits if you
absolutely want to.
------------------------------
Date: Tue, 02 Nov 1999 14:39:34 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Extract string ?
Message-Id: <381F6826.5F6DEE78@mail.cor.epa.gov>
Adrian Chin wrote:
>
> Hi
Howdy
> I have :
>
> vol1/extract/inst/sum.C:1:2:3
> vol2/extract/algo.h:2:3:4
> vol3/extr/rol/rojak/bunga/fungi.sh:1:2:3
>
> in a file call file.txt. How do I extract the colored string out to a
> variable in perl ?
Please please please don't send MIME to text-only newsgroups.
Among other things, people with normal newsreaders will not
be able to tell what part of your strings are 'colored'.
But you apparently want to match everything between the last
slash and the first colon. That's straightforward using
regexes. I suggest you read perlre to learn about them.
When you try a few and have some more questions, come on back.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 02 Nov 1999 14:43:36 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Extract string ?
Message-Id: <381F6918.805169D5@mail.cor.epa.gov>
Adrian Chin wrote:
>
> This works too, thanks.
>
> if ($file =~ /.*\//)
> {
> $shift = "$'\n";
> print "$shift";
> }
It does? For what definition of the word 'works'? It will
print out everything after the last slash, which is *not*
what you asked for.
And it is not a good idea to blindly slap everything into
quotes for your print() . That will bite you eventually.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 02 Nov 1999 14:44:26 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Extract string ?
Message-Id: <381F694A.162466E1@mail.cor.epa.gov>
Larry Rosler wrote:
>
> In article <381E535E.7EB1630B@inprise.com> on Tue, 02 Nov 1999 10:58:38
> +0800, Adrian Chin <Achin@inprise.com> says...
> ...
> > vol1/extract/inst/sum.C:1:2:3
> > vol2/extract/algo.h:2:3:4
> > vol3/extr/rol/rojak/bunga/fungi.sh:1:2:3
> >
> > in a file call file.txt. How do I extract the colored string out to a
> > variable in perl ?
>
> In neither of your almost identical posts do I see any colored strings.
> It all seems black and white to me.
Hmm. Maybe you need to see an opthamologist about that. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 2 Nov 1999 17:58:28 -0500
From: dha@panix.com (David H. Adler)
Subject: Re: FAQ 2.14: What mailing lists are there for perl?
Message-Id: <slrn81ur4i.7mh.dha@panix.com>
On Mon, 01 Nov 1999 03:00:18 -0500, brian d foy <brian@smithrenaud.com> wrote:
>In article <x7puxubt7g.fsf@home.sysarch.com>, Uri Guttman <uri@sysarch.com> wrote:
>
>>>>>>> "GK" == Graeme Kennedy <graeme@seercom.com> writes:
>> GK> In article <381bc4f6@cs.colorado.edu>,
>> perlfaq-suggestions@perl.com (Tom
>> GK> and Gnat) wrote:
>>
>> >> http://www.perl.org/maillist.html
>>
>> GK> This FAQ has been out of date for some time. The URL does not exist.
>>
>> GK> http://www.perlmongers.org/support/online_support.html#mail
>>
>>mail that fix to the perlfaq address. tom and gnat don't frequent this
>>group much these days.
>
>i've already set that in motion, and have also set up a temporary
>RewriteRule so that the user ends up at the right place with either
>address. ;)
FYI, FWIW, the patch has been submitted to p5p.
Acronymically yours,
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
This is Pop - XTC
------------------------------
Date: Tue, 02 Nov 1999 22:48:37 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Formatting a Date Properly
Message-Id: <9TJT3.22485$23.1156010@typ11.nn.bcandid.com>
In article <7vn5qi$6hn$1@nnrp1.deja.com>, <reedjd@bitsmart.com> wrote:
>I'm having an issue formatting a date to be used by a shell. I've
>been trying to compress it into one line:
Why are you doing that? Are you trying to ensure job security for
yourself, or do you just hate whoever you're writing this code for?
For Perl Golf and punched cards, minimizing code size is fine. For
anything else, maximize clarity instead.
>perl -e '($d,$m,$y)=(localtime(time))[3..5];$m+=1;$y+=1900;print
>sprintf "%4.0d%2.0d%2.0d\n",$y,$m,$d;'
BTW, the stuff after the decimal point (zeroes here) is called the
"precision" -- it's what you'd think it would be for %f, but for %d, it
specifies a minimum width. So it's unnecessary, since that's what's
before the decimal point too.
Jeff Pinyan answered your question correctly.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Tue, 02 Nov 1999 14:55:48 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Help!!! Need Net::Ping to work ASAP!
Message-Id: <381F6BF4.283D0529@mail.cor.epa.gov>
Richard Lawrence wrote:
>
> Hi all,
Howdy,
> I've got a bit of a strange problem with Net::Ping. Basically it
> doesn't work. Here is the code spooned straight out of the man page:
[snip]
> I run this and get the following error:
>
> Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
> 16 at /usr/lib/perl5/5.00503/i386-linux/Socket.pm line 295.
>
> What on earth is going on? Have I done something wrong? I tried
> changing it to the IP address but that didn't work either. I tried
> "localhost" and "127.0.0.1" and all of them produce the same error.
It looks like your socket constants are wrong. Did you compile
Perl yourself? If so, you may have made an error. Is this
Perl on a RedHat linux box? Maybe 5.2 or 6.0? If so, you'll
want to search on this in the deja.com archives of this newsgroup,
because RH has given you a broken Perl.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 2 Nov 1999 13:09:19 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Hiding Perl Scripts?
Message-Id: <Pine.GSO.4.10.9911021308190.29670-100000@user2.teleport.com>
On Tue, 2 Nov 1999, Chris Beels wrote:
> If your server allows executables, try perl2exe
If the program wasn't hidden before using perl2exe, it's not hidden after
using it. Oh, well!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 02 Nov 1999 14:59:21 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Hiding Perl Scripts?
Message-Id: <381F6CC9.A1AE06C7@mail.cor.epa.gov>
Chris Beels wrote:
>
> Mike,
>
> If your server allows executables, try perl2exe from Mercury Systems at
> http://www.perl2exe.com/
Chris, if his program can be viewed, the executable can still be
viewed. If his program can be modified, his executable can be, as
well. Perl2Exe doesn't solve this problem. If compiling solved this
problem, Microsoft wouldn't have any piracy problems, would they?
Mike needs to check that the server is set up properly.
And please, when you post, follow Usenet etiquette and put your
reply *after* the text. It's the polite way to make threads possible.
> LorainCounty.com Webmaster <webmaster@LorainCounty.com> wrote in message
[stuff snipped]
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 2 Nov 1999 13:24:39 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How do I create a library file of subroutines?
Message-Id: <Pine.GSO.4.10.9911021322580.29670-100000@user2.teleport.com>
On 2 Nov 1999, Eric Dew wrote:
> Subject: How do I create a library file of subroutines?
>
> I haven't seen this in the perl FAQ, but maybe because I'm not using the
> correct words.
Look at the information about 'require' in the perlfunc manpage. But you
should also consider making a module; see the perlmod manpage.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 2 Nov 1999 12:31:52 -0800
From: moseley@best.com (Bill Moseley)
Subject: HTTP::Date
Message-Id: <MPG.1288ea0f51acd21f989831@nntp1.ba.best.com>
I'm using HTTP::Date::str2time() to convert the If-Modified-Since:
header. It fails on this sent by Netscape:
Tuesday, 02-Nov-99 20:15:45 GMT; length=20119
Is there a HTTP::* method somewhere that will convert this date, or do I
need to strip the ; length=20119 myself?
Thanks,
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: 02 Nov 1999 22:09:49 +0100
From: Gisle Aas <gisle@aas.no>
Subject: Re: HTTP::Date
Message-Id: <m3ogdclhwi.fsf@eik.g.aas.no>
moseley@best.com (Bill Moseley) writes:
> I'm using HTTP::Date::str2time() to convert the If-Modified-Since:
> header. It fails on this sent by Netscape:
>
> Tuesday, 02-Nov-99 20:15:45 GMT; length=20119
>
> Is there a HTTP::* method somewhere that will convert this date, or do I
> need to strip the ; length=20119 myself?
There is no support for such stupidity yet. Perhaps we could make
the $h->if_modified_since method known about this?
--
Gisle Aas
------------------------------
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 V9 Issue 1257
**************************************