[28040] in Perl-Users-Digest
Perl-Users Digest, Issue: 9404 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 28 21:05:40 2006
Date: Wed, 28 Jun 2006 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 28 Jun 2006 Volume: 10 Number: 9404
Today's topics:
global variables in a web service <sal.x.lopez@gmail.com>
Re: global variables in a web service <el.dodgero@gmail.com>
Re: How to ignore 1st line in a file when reading <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: How to ignore 1st line in a file when reading <jgibson@mail.arc.nasa.gov>
Re: How to ignore 1st line in a file when reading <el.dodgero@gmail.com>
Re: How to ignore 1st line in a file when reading <el.dodgero@gmail.com>
Re: How to ignore 1st line in a file when reading <someone@example.com>
Re: How to pass an array and scalar as arguments to a s <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Is this a Hash and how can I test a value? <tadmc@augustmail.com>
Re: Malformed utf8; where's the null byte coming from? <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Printing Hash of Array of Arrays <jgibson@mail.arc.nasa.gov>
reading in a nested formatted data structure with quirk el.dodgero@gmail.com
Re: reading in a nested formatted data structure with q <jgibson@mail.arc.nasa.gov>
Re: reading in a nested formatted data structure with q el.dodgero@gmail.com
Re: reading in a nested formatted data structure with q el.dodgero@gmail.com
Re: reading in a nested formatted data structure with q <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: replacement of slow unpack <u8526505@gmail.com>
Re: replacement of slow unpack xhoster@gmail.com
Re: replacement of slow unpack <someone@example.com>
Re: Single-liner for one-line substitute? <xicheng@gmail.com>
Re: Single-liner for one-line substitute? <someone@example.com>
Re: Single-liner for one-line substitute? <xicheng@gmail.com>
Re: WIN32 PPM and perldoc problems jovo.miskin@sciatl.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jun 2006 15:44:32 -0700
From: "sal.x.lopez@gmail.com" <sal.x.lopez@gmail.com>
Subject: global variables in a web service
Message-Id: <1151534672.154508.218940@j72g2000cwa.googlegroups.com>
How do I set global variables in a web service script so that they are
available to all functions? In my code below, and when called by the
client, the variable $str is empty within the helloWorld subroutine.
#!/bin/perl
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
->dispatch_to('DEMO')
->handle;
package DEMO;
my $str = "Hello World";
sub helloWorld {
my ($arg1, $arg2) = @_;
print "$str\n";
# do other stuff
}
------------------------------
Date: 28 Jun 2006 17:16:36 -0700
From: "Dodger" <el.dodgero@gmail.com>
Subject: Re: global variables in a web service
Message-Id: <1151540196.299579.174530@m73g2000cwd.googlegroups.com>
sal.x.lopez@gmail.com wrote:
> How do I set global variables in a web service script so that they are
> available to all functions? In my code below, and when called by the
> client, the variable $str is empty within the helloWorld subroutine.
>
> #!/bin/perl
>
> use SOAP::Transport::HTTP;
> SOAP::Transport::HTTP::CGI
> ->dispatch_to('DEMO')
> ->handle;
>
> package DEMO;
>
> my $str = "Hello World";
>
> sub helloWorld {
>
> my ($arg1, $arg2) = @_;
>
> print "$str\n";
>
> # do other stuff
>
> }
For that case, use our() not my(), or predeclare the variable.
our() creates a package global.
This is not necessarily a true global, especially in a webserver
environment. That's probably what you want. I know you asked for a true
global, but I have some doubt as to whether you really want a true
global -- such would be shared with other requests and things and could
be bad: consider:
User 'schmoo' logs in and has the $handle variable set. You've made
this a true global.
Another user comes in and doesn't log in. The script is set to say
'Welcome, Guest' if the $handle variable isn't set or 'Welcome $handle'
if it is. You'd expect the second user to see 'Welcome Guest' but if
nothing specifically unsets $handle from being 'Schmoo' and $handle is
a true global, the unlogged in user will see 'Welcome Schmoo' instead.
This could be bad if, for instance, you have private information,
administrative functions, or consumer downloadables, for instance.
Secondly, such true globals will only be true to the server process
that they start in. Sone most webservers have anywhere form 5 to 500
child processes running to handle the traffic at one time, those would
be all entirely seperate processes.
So yeah, it's probably a package global you want, and therefore
our $variable = 'FooBar'
------------------------------
Date: Wed, 28 Jun 2006 22:52:13 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <xKDog.274$vt2.73@newsread2.news.pas.earthlink.net>
Tim Hammerquist wrote:
>
> Here's my solution, very similar to another poster's:
>
> open FH, "<filename" or die "can't open: $!";
> <FH>; # discards first line [...]
No, it probably discards the file. In a list context (the default), <FH>
returns a list of all the the remaining lines in the file. To get a
single line, do this:
scalar <FH>;
HTH
------------------------------
Date: Wed, 28 Jun 2006 16:09:51 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <280620061609515383%jgibson@mail.arc.nasa.gov>
In article <xKDog.274$vt2.73@newsread2.news.pas.earthlink.net>, Mumia
W. <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
> Tim Hammerquist wrote:
> >
> > Here's my solution, very similar to another poster's:
> >
> > open FH, "<filename" or die "can't open: $!";
> > <FH>; # discards first line [...]
>
> No, it probably discards the file. In a list context (the default), <FH>
> returns a list of all the the remaining lines in the file. To get a
> single line, do this:
>
> scalar <FH>;
Easy to test:
#!/usr/local/bin/perl
#
use strict;
use warnings;
<DATA>;
print <DATA>;
__DATA__
line 1
line 2
line 3
line 4
Produces:
line 2
line 3
line 4
So would you like to revise your statement?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 28 Jun 2006 17:07:51 -0700
From: "Dodger" <el.dodgero@gmail.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <1151539671.058867.247220@x69g2000cwx.googlegroups.com>
Deepu wrote:
> Sorry for my incorrect statement.
>
> Brian Wakem wrote:
> > Deepu wrote:
> > > Hi all,
> > >
> > > I would like to know when reading a file which has around 10 - 20 lines
> > > in it. How can it be done to ignore 1st line and start reading from 2nd
> > > till last.
> > >
> > > Example:
> > >
> > > FILE0 ## the name will not be same in all the other files ##
> > > FILE1
> > > FILE2
> > > FILE3
> > > FILE4
> > > FILE5
> > >
> > > Now i need to read from 2nd line. Can somebody please help me on this.
> > >
> > > To read the whole file, i just use:
> > >
> > > open (FH, "FileName") || die "Can't open";
> > >
> > > while (<FH>) {
> > > push (@array, $_);
> > > }
> >
> > If you are reading into an array then your question may as well be about
> > skipping the first element of an array.
>
> I am not reading into an array.
>
> basically i will take each line and compare with a pattern.
It's pretty simple to just skip a line...
my $skipped = 0;
while (<FILE>) {
unless ($skipped) {
$skipped = 1;
next;
}
# do something with the line
}
------------------------------
Date: 28 Jun 2006 17:26:13 -0700
From: "Dodger" <el.dodgero@gmail.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <1151540773.256352.168590@b68g2000cwa.googlegroups.com>
Jim Gibson wrote:
> In article <xKDog.274$vt2.73@newsread2.news.pas.earthlink.net>, Mumia
> W. <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
>
> > Tim Hammerquist wrote:
> > >
> > > Here's my solution, very similar to another poster's:
> > >
> > > open FH, "<filename" or die "can't open: $!";
> > > <FH>; # discards first line [...]
> >
> > No, it probably discards the file. In a list context (the default), <FH>
> > returns a list of all the the remaining lines in the file. To get a
> > single line, do this:
> >
> > scalar <FH>;
Jim and Tim are right. Mumia is half right.
Yes, in a list context <FH> would discard the whole file.
However, on a line by itself, <FH> is not in list context. It's in
scalar context and thus just pulls one line, just like when it's in the
well-known while (<FH>) {} block (as the () on a while indicate a
conditional, not a list context).
I haven't tested it, but I'd be more wary of the possibility of Mumia's
suggestion doing what Mumia wants to avoid. Since scalar() explicitly
casts something into scalar context, I'd be concerned that it
implicitly treats it in a list context to do so, which, if the case,
would have the paradoxical effect of slupring the whole file and
returning the number of lines in it. Then again, the whole 'DWIM'
philosophy might mean that such a case is checked for beforehand behind
the scenes and that situation avoided. Again, I'm not sure on that one
either way. I'd have to try it, and I'm not gonna right now. But it
would have me more wary than just the implicitly scalar <FH> by itself,
as statements are in scalar context unless stated otherwise.
------------------------------
Date: Thu, 29 Jun 2006 00:44:04 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <onFog.103483$S61.59253@edtnps90>
Dodger wrote:
> Jim Gibson wrote:
>>In article <xKDog.274$vt2.73@newsread2.news.pas.earthlink.net>, Mumia
>>W. <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
>>
>>>Tim Hammerquist wrote:
>>>>Here's my solution, very similar to another poster's:
>>>>
>>>>open FH, "<filename" or die "can't open: $!";
>>>><FH>; # discards first line [...]
>>>No, it probably discards the file. In a list context (the default), <FH>
>>>returns a list of all the the remaining lines in the file. To get a
>>>single line, do this:
>>>
>>>scalar <FH>;
>
> Jim and Tim are right. Mumia is half right.
>
> Yes, in a list context <FH> would discard the whole file.
> However, on a line by itself, <FH> is not in list context. It's in
> scalar context and thus just pulls one line,
Actually it is in void context, which in this case behaves the same as scalar
context.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 28 Jun 2006 22:52:14 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: How to pass an array and scalar as arguments to a subroutine/
Message-Id: <yKDog.275$vt2.131@newsread2.news.pas.earthlink.net>
TheOrangeRemix wrote:
> I'm writing a Perl script to take in an array and a scalar as two
> arguments and pass them to a subroutine.
> Each element of the array has contents ########### word ########### and
> the scalar being passed is the size of the array.
> The subroutine is supposed to strip the '#" from the contents of each
> element and just report the "word" in one array, and report the size of
> the array in a scalar.
> [...]
>
> sub unhash
> {
> my(@fieldarray) = @_;
> my($sizearray) = shift;
>
>
> print "$sizearray\n";
>
> for ($i = 0; $i < $sizearray; $i++)
> { [...]
Hmm.
...array size provided as a separate parameter...
...using 'for' to iterate over an array...
Why do I detect a C programmer? :)
Perl stores the sizes of arrays internally and has more powerful looping
constructs for arrays than the 'for' statement:
sub unhash_array {
map m/(\w+)/ && $1, @_;
}
Learn Perl. It'll pay off ;)
And like Brian Wakem said, it's more efficient to use a reference. See
"perldoc perlref"
------------------------------
Date: Wed, 28 Jun 2006 17:14:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Is this a Hash and how can I test a value?
Message-Id: <slrnea5vqu.ukq.tadmc@magna.augustmail.com>
Jockser <qbert@comcast.net> wrote:
> $VAR1 = {
> 'lname' => 'Smith',
> 'fname' => 'John',
> 'address1' => '2500 Lemon St.',
> 'type' => 'a'
> };
>
> 1st question: Is this a Hash?
No.
$temp is a reference (to a hash).
See:
perldoc perlreftut
>
> 2nd question: How can I check to see if 'type' is = to 'a' or 'b' ?
if ( $temp->{type} eq 'a' or $temp->{type} eq 'b' ) {
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 29 Jun 2006 00:31:18 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Malformed utf8; where's the null byte coming from?
Message-Id: <qbFog.4283$ii.1680@newsread3.news.pas.earthlink.net>
bill_mckinnon@interloper.net wrote:
> I've spent some time trying to understand Perl's Unicode support and
> its nuances, and I think I actually understand some amount of it. But
> the behavior of this snippet of code is puzzling me at the moment:
>
> --
> #!/usr/local/bin/perl -w
>
> use Encode qw(decode);
>
> $s = decode('utf8', "Version"); # String w/utf8 flag set
> $s =~ s/v\xc3\x83//i;
> --
> [...]
I was able to eliminate the warning by using "use encoding 'utf8'," but
there is a problem with the substitution.
use Encode qw(decode);
use encoding 'utf8';
my $s;
# rx is "vÃ"
my $rx = qq{"v\xc3\x83"};
$s = decode('utf8', "V\x{c3}\x{83}ersion"); # String w/utf8 flag set
print 'rx : ', $rx, "\n";
print 'before: ', $s, "\n";
$s =~ s/v\xc3\x83//i;
print 'after : ', $s, "\n";
__END__
This prints this:
rx : "vÃ"
before: V�ersion
after : �ersion
Notice that the "�" wasn't substituted even though the 'V' was. Why?
------------------------------
Date: Wed, 28 Jun 2006 15:24:13 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Printing Hash of Array of Arrays
Message-Id: <280620061524134316%jgibson@mail.arc.nasa.gov>
In article <1151522240.528043.51050@75g2000cwc.googlegroups.com>, Deepu
<pradeep.bg@gmail.com> wrote:
> Hi All,
>
> How to print hash of array of arrays without using Data::Dumper.
>
> I am trying to print
>
> %hash = (
[hash of array of arrays snipped]
> foreach my $key (sort keys %hash) {
> print "$key\n"; ## - It prints the file names correctly as keys
>
> for $i (0 .. $#{$hash{$key}}) {
> print "$i: $hash{$key}[$i]";
> }
> }
>
> But now i get output like:
>
> 0: ARRAY(0x5fdbf0)
> and so on.
It is telling you that $hash{$key}[$i] is an array reference, which you
already should have known. You need to dereference the array. Either
print it as an interpolated string:
print "row $i: @{$hash{$key}[$i]}\n";
or iterate over the elements and print each one:
foreach my $key (sort keys %hash) {
print "$key\n";
for my $i ( 0 .. $#{$hash{$key}} ) {
for my $j ( 0 .. $#{$hash{$key}[$i]} ) {
print " [$i,$j]: ${${$hash{$key}}[$i]}[$j]\n";
}
}
}
------------------------------
Date: 28 Jun 2006 15:15:24 -0700
From: el.dodgero@gmail.com
Subject: reading in a nested formatted data structure with quirks
Message-Id: <1151532924.723364.198560@y41g2000cwy.googlegroups.com>
I'm having a brainfart day, so I'll just throw this up to see if
there's some easy solution already out there that I don't know about...
I have data in a format that looks like it should be easy to parse, but
it's not acting that way...
For the most part, most of the data is in a simple sort of structure,
like so:
something whatever:2
{
property blah
otherproperty blahblah
}
However some of the time it's more like this:
something foo:3
{
property blah
otherthings
{
otherthingType1 identifier
{
property1 1
property2 2
moreInfoThanYouNeed
{
data 1 yadda
data 2 yaddayadda
data 3 yaddayaddayadda
}
}
otherthingType2 identifier
{
property1 0
property2 foo
}
}
The trick is that the whole {} block of anything is one biug property
of the stuff above it. The nesting could go on and on forever in theory
though normally sits at about 0-5 deep
I'm wanting to parse this stuff into a data structure. The thing is, if
I go line by line, then by the time I'm at a { line to know I'm in a
subnested block, I've already passed by the thing I have to set it as a
property of. Thus I'm thinking two things:
1) The reading-in of any given {} block should be a subroutine that
knows to call itself. This makes it convenient that all these files
start and end with a { and } respectively, putting the whole thing
inside a big block like this.
2) I should keep a reference to the last thingy I set, the previous
token, so to speak.
3) I should make a simple little subroutine called 'assign' that
simplifies the process of assigning a property to a token that may
already have it -- since I don't want to redefine such property of a
token, I should assign or append to an array. Since I don't know what
will need an array ahead of time for sure, a subroutine that handles
the assigning would be good, something like this:
sub assign ($$) {
my $thing = shift;
my $newval = shift;
if (defined $thing) {
unless (ref $thing eq 'ARRAY') {
$thing = [$thing];
}
push @{$thing}, $newval;
}
else {
$thing = $newval;
}
}
But anything i'm not thinking of... well, I can't exactly ask 'Am I not
thinking of this?' if I have no clue that 'this' may be. So this is
sort of that whole 'pointing and question marks' thing....
BTW if no one answers this, it's okay.
This is sort of therapeutic to write it all out like this too.
Who knows, maybe someone else has a similar scenario where my thoughts
will help them. *shrug*
BTW -- the vasy majority will either pass this by without a second
thought, suggest things to me that will help, or say that something I
said helped them with their problem. The first don't bother me, the
second I thank (and will, not just in advance), and the third, no
worries.
However, there is someone out there who's wanting to answer this in
some asshole way just to get some smartass comment in for no good
reason than their own narcissistic joy at seeing the oh-so-clever thing
they typed. I know this deep in my soul because I know this is usenet.
So, if you are that person, just get a life instead, ok?
------------------------------
Date: Wed, 28 Jun 2006 16:28:04 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: reading in a nested formatted data structure with quirks
Message-Id: <280620061628040999%jgibson@mail.arc.nasa.gov>
In article <1151532924.723364.198560@y41g2000cwy.googlegroups.com>,
<el.dodgero@gmail.com> wrote:
> I'm having a brainfart day, so I'll just throw this up to see if
> there's some easy solution already out there that I don't know about...
>
> I have data in a format that looks like it should be easy to parse, but
> it's not acting that way...
>
> For the most part, most of the data is in a simple sort of structure,
> like so:
>
[nested data structure snipped]
> BTW -- the vasy majority will either pass this by without a second
> thought, suggest things to me that will help, or say that something I
> said helped them with their problem. The first don't bother me, the
> second I thank (and will, not just in advance), and the third, no
> worries.
>
> However, there is someone out there who's wanting to answer this in
> some asshole way just to get some smartass comment in for no good
> reason than their own narcissistic joy at seeing the oh-so-clever thing
> they typed. I know this deep in my soul because I know this is usenet.
> So, if you are that person, just get a life instead, ok?
Hey! You are trying to take all the fun out of Usenet for some people!
This sounds like a job for Parse::RecDescent. You will have to define a
grammar for your file format, and it might be overkill, but it would be
a good opportunity to learn the technique.
I would also consider putting the whole file into one scalar and
picking it apart with Text::Balanced.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 28 Jun 2006 16:52:47 -0700
From: el.dodgero@gmail.com
Subject: Re: reading in a nested formatted data structure with quirks
Message-Id: <1151538767.622898.64480@d56g2000cwd.googlegroups.com>
Jim Gibson wrote:
> In article <1151532924.723364.198560@y41g2000cwy.googlegroups.com>,
> <el.dodgero@gmail.com> wrote:
>
> > I'm having a brainfart day, so I'll just throw this up to see if
> > there's some easy solution already out there that I don't know about...
> >
> > I have data in a format that looks like it should be easy to parse, but
> > it's not acting that way...
> >
> > For the most part, most of the data is in a simple sort of structure,
> > like so:
> >
>
> [nested data structure snipped]
>
>
> > BTW -- the vasy majority will either pass this by without a second
> > thought, suggest things to me that will help, or say that something I
> > said helped them with their problem. The first don't bother me, the
> > second I thank (and will, not just in advance), and the third, no
> > worries.
> >
> > However, there is someone out there who's wanting to answer this in
> > some asshole way just to get some smartass comment in for no good
> > reason than their own narcissistic joy at seeing the oh-so-clever thing
> > they typed. I know this deep in my soul because I know this is usenet.
> > So, if you are that person, just get a life instead, ok?
>
> Hey! You are trying to take all the fun out of Usenet for some people!
Well, you know *L*
> This sounds like a job for Parse::RecDescent. You will have to define a
> grammar for your file format, and it might be overkill, but it would be
> a good opportunity to learn the technique.
I will look at this, thanks.
> I would also consider putting the whole file into one scalar and
> picking it apart with Text::Balanced.
I actually considered it, but...
The actual files are Curious Labs Poser markup files (CR2, HR2, PP2,
PZ2, etc). While some are relatively smallish, others contain morph
targets and custom geometry --
As a for-instance, Victoria 2 from daz3d.com (a bit of an older model,
but still the best example) contains some 100-odd morphs in her CR2
file.Each of these morphs is composed of up to some 10,000 odd vertex
deltas (and if a newer figure was all-in-one like this it would be
worse -- the geometry for Victoria 3 is 72,712 vertices for the full
figure's mesh, and half that in the head:1 actor -- if that had the
same number of morphs in the CR2 itself like V2 did, augh!). As it is,
V2's CR2 file is already some 20MB. Somehow I'm thinking that a 20MB
scalar... not such a good idea B^)
And yeah that's my bad -- I didn't indicate the potential for hugeness
these files might get to.
Thanks!
------------------------------
Date: 28 Jun 2006 16:59:54 -0700
From: el.dodgero@gmail.com
Subject: Re: reading in a nested formatted data structure with quirks
Message-Id: <1151539194.761662.20340@i40g2000cwc.googlegroups.com>
Jim Gibson wrote:
> In article <1151532924.723364.198560@y41g2000cwy.googlegroups.com>,
> <el.dodgero@gmail.com> wrote:
> I would also consider putting the whole file into one scalar and
> picking it apart with Text::Balanced.
Oooh, thanks again actually...
'cause ... well... now that I think about it (and had a better think
about why I didn't go that route)...
I could theoretically take out all the morphs and custom geeomtry
*first*... store them out seperately and then put a marker of some sort
that indicates that I mean to reference those there...
Like, a morph deltas' subblock looks like this:
deltas
{
d 1 .00004 .00032 -.00045
d 2 .00003 .00031 -.00041
...
d 1754 .00024 -.00415 .00012
}
Where the ... means all or most of the numbers I skipped (ones where
the results would be like d i 0 0 0 are left out thankfully) -- but if
I pulled that out, stored it in an array in a hash, or even in a DBM or
something --- I could then refer to that by replacing it like, for
instance:
deltas
{
deltasref 1
}
And the same for embedded meshes...
ANd then *that* would all fit in a scalar because it would be hard
pressed to be more than a few k, and usually far less. It's jus tthe
deltas and geometry that kill things.
------------------------------
Date: Thu, 29 Jun 2006 00:31:19 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: reading in a nested formatted data structure with quirks
Message-Id: <rbFog.4284$ii.3850@newsread3.news.pas.earthlink.net>
el.dodgero@gmail.com wrote:
> I'm having a brainfart day, so I'll just throw this up to see if
> there's some easy solution already out there that I don't know about...
>
> I have data in a format that looks like it should be easy to parse, but
> it's not acting that way...
> [...]
It's complicated enough that you might want to use the Text::Balanced
module and a custom-made recursive subroutine.
------------------------------
Date: 28 Jun 2006 15:07:15 -0700
From: "cyl" <u8526505@gmail.com>
Subject: Re: replacement of slow unpack
Message-Id: <1151532435.442407.154500@y41g2000cwy.googlegroups.com>
John W. Krahn =E5=AF=AB=E9=81=93=EF=BC=9A
>
> Yes it is slow, but it is faster then the alternatives. The lesson here =
is
> try to use the contents of $x without dividing it up into individual char=
acters.
>
In my case, the contents are network packet. If I don't unpack it, is
there other way to analyze it (like parsing IP header) with the binary
string?
------------------------------
Date: 28 Jun 2006 22:19:09 GMT
From: xhoster@gmail.com
Subject: Re: replacement of slow unpack
Message-Id: <20060628181937.878$vF@newsreader.com>
"cyl" <u8526505@gmail.com> wrote:
> John W. Krahn =E5=AF=AB=E9=81=93=EF=BC=9A
>
> >
> > Yes it is slow, but it is faster then the alternatives. The lesson
> > here =
> is
> > try to use the contents of $x without dividing it up into individual
> > char=
> acters.
> >
>
> In my case, the contents are network packet. If I don't unpack it, is
> there other way to analyze it (like parsing IP header) with the binary
> string?
Don't unpack the whole thing, just the header.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 28 Jun 2006 22:39:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: replacement of slow unpack
Message-Id: <DyDog.83399$I61.58855@clgrps13>
cyl wrote:
> John W. Krahn 寫道:
>
>>Yes it is slow, but it is faster then the alternatives. The lesson here is
>>try to use the contents of $x without dividing it up into individual characters.
>
> In my case, the contents are network packet. If I don't unpack it, is
> there other way to analyze it (like parsing IP header) with the binary
> string?
It depends on how you want to analyse it.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Jun 2006 15:05:55 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: Single-liner for one-line substitute?
Message-Id: <1151532355.476498.37980@j72g2000cwa.googlegroups.com>
Mike Pearson wrote:
> Hi -
>
> I know almost no Perl at all, but I occasionally use
>
> perl -pi -e 's/old/new/g' file
>
> for a global search/replace in a file. I've tried to modify this to
> change only a string on the first line of a file, leaving the string
> unchanged elsewhere in the file, but I haven't been able to find a way
> to do this. Simply removing the 'g' has no effect - it still does a
> global replace.
>
> Can anyone tell me how to do this?
>
For multiple files, replace only in the first line:
perl -0777pe 's/^(.*?)old/$1new/' file*
Xicheng
------------------------------
Date: Wed, 28 Jun 2006 22:34:49 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Single-liner for one-line substitute?
Message-Id: <duDog.21578$B91.3509@edtnps82>
Xicheng Jia wrote:
> Mike Pearson wrote:
>>
>>I know almost no Perl at all, but I occasionally use
>>
>>perl -pi -e 's/old/new/g' file
>>
>>for a global search/replace in a file. I've tried to modify this to
>>change only a string on the first line of a file, leaving the string
>>unchanged elsewhere in the file, but I haven't been able to find a way
>>to do this. Simply removing the 'g' has no effect - it still does a
>>global replace.
>>
>>Can anyone tell me how to do this?
>>
>
> For multiple files, replace only in the first line:
>
> perl -0777pe 's/^(.*?)old/$1new/' file*
But that only substitutes one 'old' for one 'new' while the original does it
for all 'old's in the line.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Jun 2006 15:48:51 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: Single-liner for one-line substitute?
Message-Id: <1151534931.846400.41940@b68g2000cwa.googlegroups.com>
John W. Krahn wrote:
> Xicheng Jia wrote:
> > Mike Pearson wrote:
> >>
> >>I know almost no Perl at all, but I occasionally use
> >>
> >>perl -pi -e 's/old/new/g' file
> >>
> >>for a global search/replace in a file. I've tried to modify this to
> >>change only a string on the first line of a file, leaving the string
> >>unchanged elsewhere in the file, but I haven't been able to find a way
> >>to do this. Simply removing the 'g' has no effect - it still does a
> >>global replace.
> >>
> >>Can anyone tell me how to do this?
> >>
> >
> > For multiple files, replace only in the first line:
> >
> > perl -0777pe 's/^(.*?)old/$1new/' file*
>
> But that only substitutes one 'old' for one 'new' while the original does it
> for all 'old's in the line.
>
then:
perl -i -0777pe 's/(?:\G|^)(.*?)old/$1new/g' file*
Xicheng :-)
------------------------------
Date: 28 Jun 2006 15:06:16 -0700
From: jovo.miskin@sciatl.com
Subject: Re: WIN32 PPM and perldoc problems
Message-Id: <1151532376.400773.167730@b68g2000cwa.googlegroups.com>
Dr.Ruud wrote:
> jovo.miskin@sciatl.com schreef:
> > I ahve installed Active Perl v5.8.7 build 813 on WindowsXP machine.
> >
> > Executing PPM gives this output:
> > C:\Perl\bin>ppm
> > Unknown or ambiguous command '*'; type 'help' for commands.
>
>
> Try these:
>
> C:> assoc .pl
> C:> ftype Perl
> C:> assoc .bat
> C:> ftype batfile
>
> I get these answers:
>
> .pl=Perl
> Perl="C:\Perl\bin\perl.exe" "%1" %*
> .bat=batfile
> batfile="%1" %*
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."
I am getting the same output:
C:\Documents and Settings\miskinj>assoc .pl
.pl=Perl
C:\Documents and Settings\miskinj>ftype Perl
Perl="C:\Perl\bin\perl.exe" "%1" %*
C:\Documents and Settings\miskinj>assoc .bat
.bat=batfile
C:\Documents and Settings\miskinj>ftype batfile
batfile="%1" %*
C:\Documents and Settings\miskinj>
Thanks,
Jovo
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9404
***************************************