[28622] in Perl-Users-Digest
Perl-Users Digest, Issue: 9986 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 20 09:05:39 2006
Date: Mon, 20 Nov 2006 06: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 Mon, 20 Nov 2006 Volume: 10 Number: 9986
Today's topics:
Re: '\0' like in C <spamtrap@dot-app.org>
Re: '\0' like in C <jurgenex@hotmail.com>
Re: best practice to avoiding excessive memory usage?? <ithinkiam@gmail.com>
Re: best practice to avoiding excessive memory usage?? <ithinkiam@gmail.com>
Re: Can perl find strings over multiple lines? <magnetfreak@gmail.com>
Re: Can perl find strings over multiple lines? <mritty@gmail.com>
Re: Date::Parse mysteriously lowercases text when an un anno4000@radom.zrz.tu-berlin.de
Re: Do I *have* to use 'OOP' to use modules? anno4000@radom.zrz.tu-berlin.de
Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U c <robertospara@gmail.com>
Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U c <jurgenex@hotmail.com>
Re: Fetching input character without newline? anno4000@radom.zrz.tu-berlin.de
Re: How to change Perl's concept of a newline in regexp <robertospara@gmail.com>
Re: How to compress a big file into many zip files with anno4000@radom.zrz.tu-berlin.de
how to execute 30 transactions at a time <kalyanrajsista@gmail.com>
Re: how to execute 30 transactions at a time <noreply@gunnar.cc>
Re: Is the WxPerl a wrapper of wxWidgets library ? <rprp@gmx.net>
reg exp: helping hand needed <oli.meister@gmail.com>
Re: reg exp: helping hand needed <mritty@gmail.com>
Re: reg exp: helping hand needed <mritty@gmail.com>
Re: reg exp: helping hand needed <noreply@gunnar.cc>
Using Sockets connecting multiple clients <sujay.tukai@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Nov 2006 07:33:06 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: '\0' like in C
Message-Id: <m2k61qti0t.fsf@Sherm-Pendleys-Computer.local>
"robertospara" <robertospara@gmail.com> writes:
> But for me '\0' is the mark of the end of the array (or string we can
> say when the type is char).
If these things are true for you, then you're writing C, not Perl. They're
not true of Perl. In Perl, a string is a scalar (not an array of anything)
and may contain a null at any point, not just the end.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 20 Nov 2006 13:30:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: '\0' like in C
Message-Id: <36i8h.762$ki3.628@trndny01>
[Please do not top post, trying to repair]
[Please do not blindly fullquote]
robertospara wrote:
> Jürgen Exner napisal(a):
>> robertospara wrote:
>>> Is there something in Perl like '\0' in C?
>>
>> You mean a character with all bits zero? Yes, there is.
>
> But for me '\0' is the mark of the end of the array
In Perl the 'end' of an array is managed internally and is accessible to the
programmer in two different ways:
- $#array indicates the last used index in the array @array
- scalar(@array) indicates the number of elements in the array (usually
$#array+1 unless someone messed around with the start index of the array)
> (or string we can say when the type is char).
An array of char has nothing to do with a string. Those are two totally
disjunct and unrelated data structures.
> So when I have >>>$string = "abcd"<<< is there somewhere '\0' in the
> end?
No, why should there be? Opposite to C in Perl that horrible crutch is not
needed. If you need the length of an array then use one of the two methods
mentioned above. If you need the length of a string then just use the
length() function.
Note: of course the first has nothing, nothing at all, to do with the
second.
> ??????????????????
Would you mind fixing your keyboard?
> Ex.
> char a[10] = "abcd";
> and then we have
> a[0] = 'a' a[1]='b' a[2]='c' a[3]='d'
>>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
>
>>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
> So this is what I am talking about.
Yes, it is amazing how primitive C is when it comes to data structures. It
doesn't even know about strings and forces the programmer not only to use an
array of characters instead, but to manually(!) manage even the length of
the string. And if you are not very careful you can screw up really badly,
e.g. char a[10] = "abcdabcdabcdabcd";
Luckily Perl is far advanced in this regard:
$a = 'abcd';
is all you need to declare and define a string that contains the first 4
latin letters. And if you want to enlarge the string, then just do so:
$a = $a . 'abcdabcsabcdabcd'.
There may or may not be an array @a, too, but it would be totally unrelated
to the scalar $a.
jue
------------------------------
Date: Mon, 20 Nov 2006 11:02:07 +0000
From: Chris <ithinkiam@gmail.com>
Subject: Re: best practice to avoiding excessive memory usage??
Message-Id: <ejs1v7$6n8$1@dux.dundee.ac.uk>
Peter J. Holzer wrote:
> On 2006-11-17 14:38, Chris <ithinkiam@gmail.com> wrote:
>> I've come across the perl issue of inefficient use of memory when
>> dealing with large datasets.
>
> You aren't the first one. There are modules for dealing with large
> numeric arrays for a reason.
>
> So far I haven't needed them but searching CPAN for appropriate
> modules would certainly be among the first things I'd try. I have also
> bookmarked something called "PDL - The Perl Data Language" just in
> case I'll ever need it.
Yes. I've seen that one, it looks very useful indeed. I'm sure I'll use
it in the future.
>> With ~73000 pairs of input and outputs. The file is ~260Mb is size.
>> However when reading the file into an array with the following code
>> snippet results in 1.2Gb of memory usage:
>
> You are storing your values as strings here. Since all your values
> seem to be 7 characters long you could reduce the size of each element
> from 32 to 20 bytes, saving almost 40 %, by converting each value into
> a number:
>
> $array[$i] = [ map { $_ + 0 } split ];
>
> In reality, the space saving may be less or more, depending on the
> memory management of your perl implementation, the exact shape of your
> data and other conditions.
Indeed, the above makes almost no difference (~100Mb) to my example
code... :(
------------------------------
Date: Mon, 20 Nov 2006 11:05:50 +0000
From: Chris <ithinkiam@gmail.com>
Subject: Re: best practice to avoiding excessive memory usage??
Message-Id: <ejs266$6n8$2@dux.dundee.ac.uk>
Thanks for all the useful replies. I now have better ideas for future
memory management.
------------------------------
Date: 20 Nov 2006 05:33:46 -0800
From: "cyborg" <magnetfreak@gmail.com>
Subject: Re: Can perl find strings over multiple lines?
Message-Id: <1164029625.958051.67260@m73g2000cwd.googlegroups.com>
Give us some examples instead of just descriptions.
Some sample text, maybe, or the original plus the result you want to
achieve.
osiris@abydos.kmt wrote:
> Is it possible to search for strings in a file over multiple lines
> using a one-liner from the shell?
>
> What I want to do is find all the text between
> a line beginning with "--" or "-- " and
> ending with ")$" where '$' is, of course, the EOL char.
>
> I also would like to know how to find the exclusion
> so that the output produces everything but the enclosed string above.
> Is this possible with perl? Thanks a million.
>
> I have perl 5.8.6 on OSX 10.4 and 5.6.1 on Solaris 7.
------------------------------
Date: 20 Nov 2006 05:36:45 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Can perl find strings over multiple lines?
Message-Id: <1164029805.138922.308340@e3g2000cwe.googlegroups.com>
osiris@abydos.kmt wrote:
> Is it possible to search for strings in a file over multiple lines
> using a one-liner from the shell?
Yes, it is.
> What I want to do is find all the text between
> a line beginning with "--" or "-- " and
> ending with ")$" where '$' is, of course, the EOL char.
>
> I also would like to know how to find the exclusion
> so that the output produces everything but the enclosed string above.
> Is this possible with perl?
Yes, it is.
If you would like assistance with the demonstration of such abilities,
please read and follow the Posting Guidelines for the group. Most
specifically, please post your best attempt to solve the problem you're
having, along with a description of how your attempt is not working
sufficiently. Be sure to include example input, desired output, and
actual output.
> Thanks a million.
You're welcome.
Paul Lalli
------------------------------
Date: 20 Nov 2006 13:32:24 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Date::Parse mysteriously lowercases text when an unrelated variable is used.
Message-Id: <4sdp38Fu2pelU1@mid.dfncis.de>
Peter Scott <Peter@PSDT.com> wrote in comp.lang.perl.misc:
> On Sun, 19 Nov 2006 12:35:14 +0000, Mumia W. (reading news) wrote:
> > To reduce my boredom I took grocery_stocker's data from "At a loss how
> > to sort this file," and I wrote a program to sort it:
> >
> > 1 #!/usr/bin/perl
> > 2
> > 3 use strict;
> > 4 use warnings;
> > 5 use Date::Parse;
> > 6 my $reverser = -1;
> > 7
> > 8 my $sortfn = sub {
> > 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
> > 10 $reverser * ($c <=> $d);
> > 11 };
> > 12
> > 13 @ARGV = 'sort-long-dates.txt';
> > 14 my @data = map uc $_, grep /./, <>;
> > 15 my @sorted = sort $sortfn @data;
> > 16 print join("",@sorted), "\n";
> > 17
> >
> > The data is sorted as expected, but something strange happens:
> > Date::Parse::str2time lowercases the weekday names. I deliberately
> > capitalize everything on the line to show that only the dates are affected.
> [snip]
> > BTW, the dates are not modified if the $reverser variable is defined
> > within the $sortfn subroutine, e.g.
> >
> > 7 my $sortfn = sub {
> > 8 my $reverser = -1;
> > 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
> > 10 $reverser * ($c <=> $d);
> > 11 };
> >
> > What's going on?
> >
> > -------------------------------
> > Perl 5.8.4
> > Debian GNU/Linux 3.1
> > Date::Parse 2.27
>
> Good report. I suspect you are running into the bug reported at
> http://groups-beta.google.com/group/perl.perl5.porters/browse_thread/thread/eefb0a6227a31891/7b14af5525b9d861?hl=en
> . Maybe you could try 5.9.3 on your program and let us know. If it's not
> fixed you can dust off perlbug.
It's still in 5.9.4.
> str2time does sort() and lc() internally. Apparently the bug has
> something to do with sort subs that are closures (moving the definition of
> $reverser out of the sub does that).
It's worse than that. The use of substr() to extract the date is
also necessary to bring the bug out. Reducing the input file to
contain only the dates and writing
my ($c, $d) = map str2time( $_), ($a, $b);
shows the original uppercase dates. Changing it to
my ($c, $d) = map str2time( substr( $_, 0)), ($a, $b);
brings the bug back. So it's not only a sort routine that is a closure,
it's also the lvalue property of substr() that is involved. I don't
envy whoever is going to tackle this. It's not going to be fixed
tomorrow.
Anno
------------------------------
Date: 20 Nov 2006 12:23:49 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <4sdl2lFuoj51U1@mid.dfncis.de>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
>
> <anno4000@radom.zrz.tu-berlin.de>], who wrote in article
> <4sc41kFv2m3pU1@mid.dfncis.de>:
>
> > The real problem is that users have to know and take into account
> > implementation details of a class they're merely using.
>
> > The typical case is a hash based class you want to inherit from.
>
> I'm a little bit confused here: do you discuss "users" of the class,
> or "developers" of derived classes?
The latter, considering a user everyone who isn't author.
> AFAIU, having attributes in the language would bring absolutely no
> benefits to the "merely users". The "developers", of course, are in a
> very different situation...
You are right, it doesn't make a difference to the end user.
The contrasting situation would be development of a cluster of two or
more classes by a single developer (or team). Essentially this is the
only situation where inheritance among traditional Perl classes can
be handled because the derived class must account for implementation
details of the base class.
Anno
------------------------------
Date: 20 Nov 2006 04:48:27 -0800
From: "robertospara" <robertospara@gmail.com>
Subject: Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U can help??
Message-Id: <1164026907.584912.218110@m73g2000cwd.googlegroups.com>
my $text = 'mother and father have a son and a daughter';
>
> my $rg = qr'(mother|father)? (?{ print "\t\t(mother|father) matches:", substr($text,$-[1],$+[1]-$-[1]), "\n" })
> .*? (?{ print "\t\t.*? matches: $& \n" })
> (son|daughter) (?{ print "\t\t(son|daughter) matches:", substr($text,$-[2],$+[2]-$-[2]), "\n" })
> 'x;
>
> print "@{[ $text =~ m/$rg/g ]}";
You almost understand what I want to do.
That what U did is made by you with hands and head. I want to do
something like this automaticlly.
My input will be >>>>>text<<< and >>>regex<<< and in third window I
will have
debugger output with many colors and blinking stuff <<<like underlined
text resizing text , rotating,
moving, animated text, blare comments>>> and clouds appearing and
explaining
whatever should be explained TO SHOW PROCESS OF MATCHING ANY REGEX TO
ANY TEXT
WITH SOME ADDITIONAL INFO. ABOUT REGEXEN AND NFA
(NondeterministicFiniteAutomat) and optimalizator work description and
clues to efectivly change regex. I will use GTK2-Perl support for
GRAPHICAL stuff.
And I'm writing it in PErl.
Thanks for informations.
U are the first person who reply. Thanks very much.
On 20 Lis, 10:43, Mirco Wahab <wahab-m...@gmx.de> wrote:
> robertospara wrote: > I am involved in work under project that will visualize the process of
> > matching the regex to input text.
> > As data to highlight sub-regexes which take a part in each step of
> > matching I want to use perl debugger output from regex compilation (
> > perl -e '-re debug; $text =~/regex/'). In the doc file perldebguts is
> > very less information about subregexes position in regex that are
> > already use in matching process. If someone every wanted to do that
> > could have said the same. My question: Eny ideas to get out from
> > debugger output elements that I could highlight in each step to
> > visualize matching process.
> >
> > My last idea was that I could take from offsets (look in perldebguts if
> > don't know what I mean) the position where sub-regex is ending for
> > example :
> >
> > my_regex == son((mother)?father*)+daughter
>
> I don't really understand what your goal is here -
> and I'm none of the gurus, but I find that question
> interesting.
>
> What I guess what you want is to trace the
> Regex evaluation, sth. like
> - find the match
> - find the part of the regex that made the match
>
> If thats so, it'll be rather simple. Use code
> assertions for that, eg.
> you have a string:
>
> my $text = 'mother and father have a son and a daughter';
>
> and a regex:
>
> my $regex = qr/(mother|father)?.*?(son|daughter)/;
>
> and want to match sth. like:
>
> $text =~ /$regex/g;
>
> To know what happens upon the evaluations,
> just print out the steps:
>
> ...
> my $text = 'mother and father have a son and a daughter';
>
> my $rg = qr'(mother|father)? (?{ print "\t\t(mother|father) matches:", substr($text,$-[1],$+[1]-$-[1]), "\n" })
> .*? (?{ print "\t\t.*? matches: $& \n" })
> (son|daughter) (?{ print "\t\t(son|daughter) matches:", substr($text,$-[2],$+[2]-$-[2]), "\n" })
> 'x;
>
> print "@{[ $text =~ m/$rg/g ]}";
> ...
>
> Maybe what you really want is much more complicated,
> but don't miss the modules YAPE::Regex::Explain and
> GraphViz::Regex in addidtion to your
>
> $> perl -Mre=debug mysource.pl
>
> Regards
>
> Mirco
------------------------------
Date: Mon, 20 Nov 2006 13:35:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U can help??
Message-Id: <iai8h.3146$mM1.2513@trndny08>
robertospara wrote:
> So MONKS OF THE PERL
> ???????????????????????????????????????????????????????
> Are you still
> ALIVE?????????????????????????????????????????????????????????????
Would you mind
- not top posting?
- not full quoting?
- repairing your keyboard?
jue
------------------------------
Date: 20 Nov 2006 12:56:55 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Fetching input character without newline?
Message-Id: <4sdn0nFuq56vU1@mid.dfncis.de>
Mark <anon40629@hotmail.com> wrote in comp.lang.perl.misc:
> "DJ Stunks" <DJStunks@gmail.com> wrote:
> >
> > I think you should try using Term::ReadKey a little harder...
>
> (pours a gin & tonic...)
>
> Ok, this is as close as I can get to what I was trying to describe:
>
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> use Term::ReadKey;
>
> ReadMode 3;
> $key = "";
> print "Your input? [(Y)es|(N)o|(Q)uit]: ";
> while ($key !~ /^[y|n|q]$/i)
> {
> $key = ReadKey 0;
> }
> printf "\nYou entered $key\n";
Don't use printf() when you mean print(). What would happen if
the user entered '%'?.
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
> Actually this is probably what I _should_ have been trying
> to come up with. Incorrect responses are not echoed on
> screen; a correct response is processed.
>
> What I was _trying_ to get was the behavior that this script
> provides, with incorrect respones being echoed onscreen,
> with the list of incorrect respones growing towards the right
> until a correct resonse is eventually given. But this is probably
> a more sensible implementation.
>
> But if anyone knows how to implement this script with the
> incorrect responses echoed on screen, I would like to see it.
Just add your own echoing:
print "Your input? [(Y)es|(N)o|(Q)uit]: ";
my $key = '';
ReadMode 3;
while ( $key !~ /^[y|n|q]$/i ) {
print( $key = ReadKey 0);
}
ReadMode 0;
print "\n";
print "User chose $key\n";
Anno
------------------------------
Date: 20 Nov 2006 04:32:25 -0800
From: "robertospara" <robertospara@gmail.com>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <1164025945.666060.156780@h48g2000cwc.googlegroups.com>
Thanks Ilya now I know more :)
Ilya Zakharevich napisal(a):
> [A complimentary Cc of this posting was sent to
> R Krause
> <rkrause@searstower.org>], who wrote in article <1164007677.453234.10380@k70g2000cwa.googlegroups.com>:
> > $var = "Hello\r";
> > return 1 if( $var =~ m/^Hello$/ );
>
> > How does one change the default newline character used in pattern
> > matching operations?
>
> Usually, one won't need to do this. My bet is that you do something
> in a very far from optimal way
>
> > Is there a Perl variable that can be set?
>
> No.
>
> Hope this helps,
> Ilya
>
> P.S. Do not forget that (in //m mode) $ is just a shortcut for
> (?=\n|\z), and ^ for (?:\A|(?<=\n)). Likewise for no //m.
------------------------------
Date: 20 Nov 2006 11:39:20 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to compress a big file into many zip files with Archive::Zip?
Message-Id: <4sdif8Fuud1cU1@mid.dfncis.de>
Bo Yang <struggle@mail.nankai.edu.cn> wrote in comp.lang.perl.misc:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> anno4000@radom.zrz.tu-berlin.de :
> > Bo Yang <struggle@mail.nankai.edu.cn> wrote in comp.lang.perl.misc:
> >> -----BEGIN xxx SIGNED MESSAGE-----
> >> Hash: SHA1
> >>
> >> I want to email a big file to in my application.
> >> But the email system will only delivery attachment
> >> with no more than 20M big. So I need compress the
> >> big file into many little zip files, and email
> >> separately.
> >
> > No. Email isn't a file transfer program. Use a file transfer
> > program to send your file in one piece.
> But we have no ftp server, so we must transfer it through
> our mail server.
Then get ftp (or rsync, or scp, or rcp, or ...). If you regularly
need to transfer big files you need a tool for that.
Anno
------------------------------
Date: 20 Nov 2006 03:50:42 -0800
From: "alwaysonnet" <kalyanrajsista@gmail.com>
Subject: how to execute 30 transactions at a time
Message-Id: <1164023442.334653.232810@h54g2000cwb.googlegroups.com>
hi all,
I've a limitation with my database that it wont accept more than 30
queries at a time. i'm passing the queries as an array. if the length
of array is more than 30 , then execution is getting failed.
how can i implement so that every-time only 30 queries will be loaded
and rest will be loaded after their execution.
I believe we can just fix the length of array everytime ....but my mind
got numb thinking...
Thanks,
Raj
------------------------------
Date: Mon, 20 Nov 2006 13:51:28 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to execute 30 transactions at a time
Message-Id: <4sdmmhFuchfkU1@mid.individual.net>
alwaysonnet wrote:
> I've a limitation with my database that it wont accept more than 30
> queries at a time. i'm passing the queries as an array. if the length
> of array is more than 30 , then execution is getting failed.
>
> how can i implement so that every-time only 30 queries will be loaded
> and rest will be loaded after their execution.
while ( my @part = splice @arr, 0, 30 ) {
querydb( @part );
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 20 Nov 2006 12:10:05 +0100
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Is the WxPerl a wrapper of wxWidgets library ?
Message-Id: <45618d0d$0$49204$14726298@news.sunsite.dk>
Bo Yang wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> I think wxPerl is just a wrapper of wxWidgets library just like
> wxPython , but I found wxPerl could be used without any wxWidgets
> library installed in my computer. How wxPerl implemented? Isn't it
> a wrapper ?
Yes it is a wrapper to wxWigets. The wxWidget library is implemented as
XS C++ code.
Find more informations under http://wxperl.sourceforge.net/
ciao,
Reinhard
------------------------------
Date: 20 Nov 2006 05:21:08 -0800
From: "Oliver Meister" <oli.meister@gmail.com>
Subject: reg exp: helping hand needed
Message-Id: <1164028868.212835.247770@e3g2000cwe.googlegroups.com>
Hello all
I might ask a quite trivial question but I don't get any further -
please excuse.
The following content is held in a string "$SingleMessage".
---------------------------------------------
1035 Zxxxxxxx
2317 XXXXXXXXXXXXXXXXXXXX
940 02
:20:XXXXXX202
:25:XXX25XXXXXXXXXXXX
:28:XXXXXXXXXXXXXXXXXXXX1
X XXXXXXXXXX XX XXXXXX X XXXXXXXXXX XX XXXXXX
X XXXXXXXXXX XX XXXXXX
:60F:XXXXXXXXXXXXXXXXXXXX1
:62F:XXXX222XXXXXXXXXXX
XXXX222XXXXXXXXXXX XXXXXXXXXX XX XXXXXX
:64:XXXXXXXXXXXXXXXXXXXX
---------------------------------------------
I'd like to receive the value, where ":<nn>:" is the field seperator
and "xxxx" the value, until the next field.
In other words: I'd like to return the values in between two
seperators, selected by a seperator.
I was trying with $fld_28 =~ s/(:28:)(.*?)/$1/ ; print $1;
This prints ":28:" only ...
I guess, that the s/ option isn't suitable (?).
May somebody lend me a helping hand?
Regards,
Oliver
------------------------------
Date: 20 Nov 2006 05:45:14 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: reg exp: helping hand needed
Message-Id: <1164030314.845562.117000@m73g2000cwd.googlegroups.com>
Oliver Meister wrote:
> I might ask a quite trivial question but I don't get any further -
> please excuse.
>
> The following content is held in a string "$SingleMessage".
> ---------------------------------------------
> 1035 Zxxxxxxx
> 2317 XXXXXXXXXXXXXXXXXXXX
> 940 02
> :20:XXXXXX202
> :25:XXX25XXXXXXXXXXXX
> :28:XXXXXXXXXXXXXXXXXXXX1
> X XXXXXXXXXX XX XXXXXX X XXXXXXXXXX XX XXXXXX
> X XXXXXXXXXX XX XXXXXX
> :60F:XXXXXXXXXXXXXXXXXXXX1
> :62F:XXXX222XXXXXXXXXXX
> XXXX222XXXXXXXXXXX XXXXXXXXXX XX XXXXXX
> :64:XXXXXXXXXXXXXXXXXXXX
> ---------------------------------------------
>
> I'd like to receive the value, where ":<nn>:" is the field seperator
I think you mean that a "separator" is a colon, two digits, and another
colon. Okay, but what about ":60F:" and ":62F:" ? Are those
separators too? They don't match your description.
> and "xxxx" the value, until the next field.
> In other words: I'd like to return the values in between two
> seperators, selected by a seperator.
>
> I was trying with $fld_28 =~ s/(:28:)(.*?)/$1/ ; print $1;
> This prints ":28:" only ...
Of course it does. What were you expecting that to do? You searched
for ":28:" (saving it in $1), followed by the fewest number of
any-character (except the newline) that could be found. That of
course, is 0, so $2 is the empty string. Then you replaced everything
you matched - which, again, was only ":28:" - with whatever was in $1,
which was ":28:". So the string doesn't change at all, and $1 is
printed out after the s///. No idea what made you think that would do
anything else.
> I guess, that the s/ option isn't suitable (?).
I have no idea what that means. Are you talking about the s///
operator, or the /s option? The s/// operator is for modifying a
string. So no, you don't want to use that. You just want to pattern
match, ie, the m// operator. The /s option allows the . wildcard to
match newlines, so yes you do want that.
You want to match all the characters, including newlines, that exist
between ":28:" and the next insance of colon, two digits, colon. So do
that:
if ($fld_28 =~ /:28:(.*?):\d{2}:/){
print "Value: $1";
}
Paul Lalli
------------------------------
Date: 20 Nov 2006 05:45:26 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: reg exp: helping hand needed
Message-Id: <1164030326.647733.210850@k70g2000cwa.googlegroups.com>
Oliver Meister wrote:
> I might ask a quite trivial question but I don't get any further -
> please excuse.
>
> The following content is held in a string "$SingleMessage".
> ---------------------------------------------
> 1035 Zxxxxxxx
> 2317 XXXXXXXXXXXXXXXXXXXX
> 940 02
> :20:XXXXXX202
> :25:XXX25XXXXXXXXXXXX
> :28:XXXXXXXXXXXXXXXXXXXX1
> X XXXXXXXXXX XX XXXXXX X XXXXXXXXXX XX XXXXXX
> X XXXXXXXXXX XX XXXXXX
> :60F:XXXXXXXXXXXXXXXXXXXX1
> :62F:XXXX222XXXXXXXXXXX
> XXXX222XXXXXXXXXXX XXXXXXXXXX XX XXXXXX
> :64:XXXXXXXXXXXXXXXXXXXX
> ---------------------------------------------
>
> I'd like to receive the value, where ":<nn>:" is the field seperator
I think you mean that a "separator" is a colon, two digits, and another
colon. Okay, but what about ":60F:" and ":62F:" ? Are those
separators too? They don't match your description.
> and "xxxx" the value, until the next field.
> In other words: I'd like to return the values in between two
> seperators, selected by a seperator.
>
> I was trying with $fld_28 =~ s/(:28:)(.*?)/$1/ ; print $1;
> This prints ":28:" only ...
Of course it does. What were you expecting that to do? You searched
for ":28:" (saving it in $1), followed by the fewest number of
any-character (except the newline) that could be found. That of
course, is 0, so $2 is the empty string. Then you replaced everything
you matched - which, again, was only ":28:" - with whatever was in $1,
which was ":28:". So the string doesn't change at all, and $1 is
printed out after the s///. No idea what made you think that would do
anything else.
> I guess, that the s/ option isn't suitable (?).
I have no idea what that means. Are you talking about the s///
operator, or the /s option? The s/// operator is for modifying a
string. So no, you don't want to use that. You just want to pattern
match, ie, the m// operator. The /s option allows the . wildcard to
match newlines, so yes you do want that.
You want to match all the characters, including newlines, that exist
between ":28:" and the next insance of colon, two digits, colon. So do
that:
if ($fld_28 =~ /:28:(.*?):\d{2}:/s){
print "Value: $1";
}
Paul Lalli
------------------------------
Date: Mon, 20 Nov 2006 15:02:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reg exp: helping hand needed
Message-Id: <4sdqraFv3ic1U1@mid.individual.net>
Oliver Meister wrote:
> The following content is held in a string "$SingleMessage".
> ---------------------------------------------
> 1035 Zxxxxxxx
> 2317 XXXXXXXXXXXXXXXXXXXX
> 940 02
> :20:XXXXXX202
> :25:XXX25XXXXXXXXXXXX
> :28:XXXXXXXXXXXXXXXXXXXX1
> X XXXXXXXXXX XX XXXXXX X XXXXXXXXXX XX XXXXXX
> X XXXXXXXXXX XX XXXXXX
> :60F:XXXXXXXXXXXXXXXXXXXX1
> :62F:XXXX222XXXXXXXXXXX
> XXXX222XXXXXXXXXXX XXXXXXXXXX XX XXXXXX
> :64:XXXXXXXXXXXXXXXXXXXX
> ---------------------------------------------
>
> I'd like to receive the value, where ":<nn>:" is the field seperator
> and "xxxx" the value, until the next field.
> In other words: I'd like to return the values in between two
> seperators, selected by a seperator.
Storing the key/value pairs in a hash may or may not be what you want:
my %hash;
while ( $SingleMessage =~ /:(\w+):(.+?)(?=:\w+:|$)/gs ) {
$hash{$1} = $2;
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 20 Nov 2006 04:14:00 -0800
From: "sujay.tukai@gmail.com" <sujay.tukai@gmail.com>
Subject: Using Sockets connecting multiple clients
Message-Id: <1164024840.408437.312890@h54g2000cwb.googlegroups.com>
I am trying to establish a socket connection between one server and
multiple clients....
I have written codes for the server and the client side. But the
problems i face are
(1) i can connect one server to one client only, but i need multiple
clients.
(2) whenevr my client fails and i restart my client then i also have to
restart my server side prog too..
This is not applicable vice versa....
plz help i want to get some details like loads of my 5 client machines
using this program...
client side :
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $handle1, $line, $msg);
$host = "192.168.0.119";
$port = "3579";
# create a udp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "udp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to port $port on $host: $!";
$handle1 = IO::Socket::INET->new(Proto => "udp",
LocalPort => $port)
or die "can't connect to port $port on $host: $!";
$handle->autoflush(1);
$handle1->autoflush(1);
print STDERR "[Connected to $host:$port]\n";
while (1) {
if($handle1->recv($line, 128)) {
if($line =~ m|send|) {
print "sending\n";
$line=`w`;
my ($ave)=$line =~ m/load average:\s(.*?),/s;
$handle->send($ave);
}
}
}
server side :
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $handle1, $line, $msg);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a udp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "udp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to port $port on $host: $!";
$handle1 = IO::Socket::INET->new(Proto => "udp",
LocalPort => $port)
or die "can't connect to port $port on $host: $!";
$handle->autoflush(1);
$handle1->autoflush(1);
print STDERR "[Connected to $host:$port]\n";
while (1) {
sleep(5);
print "send\n";
$handle->send("send");
if($handle1->recv($line, 128)) {
print "$line\n";
}
}
------------------------------
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 9986
***************************************