[17480] in Perl-Users-Digest
Perl-Users Digest, Issue: 4900 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 16 03:10:38 2000
Date: Thu, 16 Nov 2000 00:10:15 -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: <974362215-v9-i4900@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 16 Nov 2000 Volume: 9 Number: 4900
Today's topics:
raw ethernet <nward@nfmail.com>
Re: raw ethernet (Martien Verbruggen)
Re: raw ethernet <nward@nfmail.com>
Re: retrieve URL from text file (Martien Verbruggen)
Re: retrieve URL from text file (Martien Verbruggen)
sleep & $anything question (Neil Cherry)
Re: sleep & $anything question (Gwyn Judd)
Re: Target of goto is too deeply nested maverner@my-deja.com
Re: Target of goto is too deeply nested <dave@iprint.com>
Re: unpack tauras6097@my-deja.com
Re: unpack (Logan Shaw)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Nov 2000 15:41:34 +1300
From: "Nathan Ward" <nward@nfmail.com>
Subject: raw ethernet
Message-Id: <JVHQ5.2931$gVqd.56295521@news.xtra.co.nz>
is there anyone here who has some code avail to help me send raw ethernet
packets? an esp interested in sending arp packets...
thx
------------------------------
Date: Thu, 16 Nov 2000 05:24:17 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: raw ethernet
Message-Id: <slrn916rr6.425.mgjv@verbruggen.comdyn.com.au>
On Thu, 16 Nov 2000 15:41:34 +1300,
Nathan Ward <nward@nfmail.com> wrote:
> is there anyone here who has some code avail to help me send raw ethernet
> packets? an esp interested in sending arp packets...
http://search.cpan.org/search?mode=module&query=ethernet
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: Thu, 16 Nov 2000 20:00:41 +1300
From: "Nathan Ward" <nward@nfmail.com>
Subject: Re: raw ethernet
Message-Id: <PLLQ5.3006$gVqd.18022512@news.xtra.co.nz>
> > is there anyone here who has some code avail to help me send raw
ethernet
> > packets? an esp interested in sending arp packets...
>
> http://search.cpan.org/search?mode=module&query=ethernet
just comes up with NetPacket::* stuff, i tried that but none of the packet
encoding (as it is called) is done yet. and as i dont know how to do it, i
cant... unless someone can point me to some code? then mabee i'll make some
generation things for NetPacket::*
------------------------------
Date: Thu, 16 Nov 2000 03:29:23 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: retrieve URL from text file
Message-Id: <slrn916l3n.425.mgjv@verbruggen.comdyn.com.au>
On Tue, 14 Nov 2000 14:37:20 -0000,
john <jpmcgowan@ireland.com> wrote:
> Sorry, here's a real example:
[Snip of the real data]
> The first line shows the format of the line I am interested in
> clearly...URL_ followed by a digit, followed by :digit: followed by a URL .
> This text does not in general start at the beginnng of a line, and as I said
> can have many slashes, periods and ampersands etc. There is plenty of other
> text around it, and also the problem of things like LinkURL_**etc** which
> look very similar, but I do not want these.
> I would like to read in each digit and the URL, possibly into arrays.
If we can assume that the URL_## you are looking for always appears on
a single line, and is never split over 2, and that there is never more
than one on a line:
#!/usr/local/bin/perl -wl
use strict;
while (<DATA>)
{
my ($link, $digit, $url) = /(?:\A|\b)(URL_\d+):(\d+):(\S+)/;
print "$link || $digit || $url" if $url;
}
(replace DATA with whatever your filehandle is). If you have the data
in a scalar:
$/ = undef;
$_ = <DATA>;
while (/(?:\A|\b)(URL_\d+):(\d+):(\S+)/g)
{
my ($link, $digit, $url) = ($1, $2, $3);
print "$link || $digit || $url";
}
If the URLs can span multiple lines, then you have whitespace in your
URL, and that shouldn't be allowed. If it's the case anyway, you'll
need to adapt the pattern to allow for this, and find a new character
that is guaranteed to terminate your URL.
Running the above against your sample data gives me:
URL_1 || 35 || http://www.dmoz.org/Sports/Hurling/
URL_2 || 41 || http://www.rte.ie/sport/indexhurling.html
Even if I add stuff in front of the URL_## lines. See the perlre
documentation for the meaning of the regular expression.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Thu, 16 Nov 2000 05:37:52 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: retrieve URL from text file
Message-Id: <slrn916skl.425.mgjv@verbruggen.comdyn.com.au>
[Your references header is broken. You should use a real usenet
reader. You should also provide a little bit of quoted context to show
us what you're responding to]
On Wed, 15 Nov 2000 12:31:49 -0800 (PST),
Test v¹ T~D~T Coalition® <testversion1@webtv.net> wrote:
> Hmmm... What if you read the file into $_ and put matches into an array
> to deal with later? Something like this:
>
> open(LINKS,"file.txt");
open (LINKS, "file.txt") or die "Cannot open file.txt: $!";
> $_=<LINKS>;
You have read only the first line of FILE into $_, unless you have
undefined $/, and you didn't show us that bit.
> close(LINKS);
>
> @Links = /\d:\d:[^\s]+/gi;
What is that /i doing there? Are your digits case sensitive?
Superfluous and unnecessary arguments are to be avoided. They don't
harm, but they do confuse people reading your code. It makes them
wonder why it is there,and they have to spend valuable time figuring
out that it has no puprose being there.
'Not a whitespace' in Perl regexen is usually expressed as \S, but
your solution is just as valid.
> foreach $i(@links){
> print "$i\n";
> }
>
> That should extract everything that's in the format of a single digit,
> followed by a colon, then another single digit and another colon,
> followed by any number of characters that isn't a whitespace (which
> seperates the URLs), then throw it into the @Links array.
Yes, it does. But the message you respond to included things that
needed to be matched that contained multiple digits between the
colons. Also, the OP only wanted to match if that string was preceded
by URL_, but not by AnythingElseURL_. Your regular expression won't
take care of that.
> Hope that works for ya...
Probably not. It doesn't meet explicitly stated requirements, nor does
it meet ones that were implicit from the data.
Martien
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Thu, 16 Nov 2000 04:48:07 GMT
From: njc@CC47532-A.ewndsr1.nj.home.com (Neil Cherry)
Subject: sleep & $anything question
Message-Id: <slrn916ppv.no8.njc@CC47532-A.ewndsr1.nj.home.com>
I have a bit of a weird problem with sleep. I tried the follwoing code
under Linux (I suspect Windows would be the same):
$Tb = 30;
sleep( $Tb );
This immediately returns instead of sleeping for 30 seconds.
sleep( 30 );
This works fine, do I have to play with pack?
--
Linux Home Automation Neil Cherry ncherry@home.net
http://members.home.net/ncherry (Text only)
http://meltingpot.fortunecity.com/lightsey/52 (Graphics)
http://linuxha.sourceforge.net/ (SourceForge)
------------------------------
Date: Thu, 16 Nov 2000 05:09:42 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: sleep & $anything question
Message-Id: <slrn916r0j.mbv.tjla@thislove.dyndns.org>
I was shocked! How could Neil Cherry <njc@CC47532-A.ewndsr1.nj.home.com>
say such a terrible thing:
>I have a bit of a weird problem with sleep. I tried the follwoing code
>under Linux (I suspect Windows would be the same):
>
>$Tb = 30;
>
>sleep( $Tb );
>
>This immediately returns instead of sleeping for 30 seconds.
Are you sure? It works okay for me. Is that cut and pasted from your
actual code?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
There is nothing so easy but that it becomes difficult when you do
it reluctantly.
-- Publius Terentius Afer
------------------------------
Date: Thu, 16 Nov 2000 02:40:45 GMT
From: maverner@my-deja.com
Subject: Re: Target of goto is too deeply nested
Message-Id: <8uvhfc$c59$1@nnrp1.deja.com>
In article <3A10584D.5B42DD1D@iprint.com>,
Dave Hodson <dave@iprint.com> wrote:
> I'm attempting to fix a bug in my code which is causing the following
> DIE msg
>
> "Target of goto is too deeply nested"
>
> I know there is an ENV var that lets me change the # of "levels" a
goto
> can climb through, but I cannot find it anywhere.
>
> Anyone know what it is?
>
> Dave
>
>
This is #defined in the perl source:
pp_ctl.c: #define GOTO_DEPTH 64
You'll need to modify the source and recompile.
Josh
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 15 Nov 2000 20:15:54 -0800
From: Dave Hodson <dave@iprint.com>
Subject: Re: Target of goto is too deeply nested
Message-Id: <3A135F7A.2C573529@iprint.com>
Thanks for the comments. I've done some more research and this actually
appears to be happening because the interpreter can't resolve the label I'm
attempting to goto (it does exist). I went over the source and it looks
like a "missing" label is handled with a different err msg. Unfortunately,
this isn't what I am seeing.
Any other ideas (besides not using a goto? I'm integrating with a 3rd party
and have no control over this call)
Dave
maverner@my-deja.com wrote:
> In article <3A10584D.5B42DD1D@iprint.com>,
> Dave Hodson <dave@iprint.com> wrote:
> > I'm attempting to fix a bug in my code which is causing the following
> > DIE msg
> >
> > "Target of goto is too deeply nested"
> >
> > I know there is an ENV var that lets me change the # of "levels" a
> goto
> > can climb through, but I cannot find it anywhere.
> >
> > Anyone know what it is?
> >
> > Dave
> >
> >
>
> This is #defined in the perl source:
>
> pp_ctl.c: #define GOTO_DEPTH 64
>
> You'll need to modify the source and recompile.
>
> Josh
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 01:58:56 GMT
From: tauras6097@my-deja.com
Subject: Re: unpack
Message-Id: <8uvf0s$a7o$1@nnrp1.deja.com>
In article <8uv6d6$648$1@doughboy.cs.utexas.edu>,
logan@cs.utexas.edu (Logan Shaw) wrote:
> In article <8uv4pf$1m7$1@nnrp1.deja.com>, <tauras6097@my-deja.com> wrote:
> >Unpacking some binary data and I'm using this:
> >
> >( @array1, $value1, @array2 ) = unpack( "C11 C C18", $binary_data );
> >
> >You would think 11 characters would go in @array1, one character in
> >$value1, and 18 characters in @array2 BUT all characters go into
> >@array1 and $value1 and @array2 DO NOT get filled. @array1 goobles up
> >everything. What gives?
>
> Actually, I'd think that the thing on the right side of
> the equals sign creates a list, and then that list is
> assigned to the list on the left side of the equals sign.
>
> And when you have an lvalue that itself is a list, then Perl goes
> through and assigns stuff to each thing into the list, giving
> each the amount of stuff that it wants. And arrays want a whole
> list, so the first array that appears gets whatever's left.
>
> Probably the easiest solution to your problem would be to tell
> Perl just what part of the arrays on the left side you want to
> write into, so that it doesn't have to assume the whole thing:
>
> ( @array1[0..10], $value1, @array2[0..17] ) =
> unpack("C11 C C18", $binary_data );
>
> One caveat here is that if $array[11] was defined before this
> statement, it'll still be defined after it, i.e. you will have
> not overwritten the entire array's contents. But you can solve
> that with a "@array1 = @array2 = ();" before the unpack.
>
> Alternatively, you could unpack into a temporary
> array and just remove what you want from there:
>
> @temp = unpack("C11 C C18", $binary_data );
> @array1 = @temp[0..10];
> $value1 = $temp[11];
> @array2 = @temp[12..29];
>
> There are other approaches too, like unpacking each part inividually,
> although that is probably too klunky.
>
> - Logan
>
Logan,
Your suggestion of using the array size declaration worked great!
( @array1[0..10], $value1, @array2[0..17] ) =
unpack("C11 C C18", $binary_data );
Thanks much. Reading about pack and unpack I'm thinking my original script
should have worked. The numeric value after the C is a repeat declaration
telling unpack how many characters (or other data types) to read in. Maybe
this is a Perl bug?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 15 Nov 2000 20:16:37 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: unpack
Message-Id: <8uvg25$6nj$1@doughboy.cs.utexas.edu>
In article <8uvf0s$a7o$1@nnrp1.deja.com>, <tauras6097@my-deja.com> wrote:
> Your suggestion of using the array size declaration worked great!
>
> ( @array1[0..10], $value1, @array2[0..17] ) =
> unpack("C11 C C18", $binary_data );
>
> Thanks much. Reading about pack and unpack I'm thinking my original script
>should have worked. The numeric value after the C is a repeat declaration
>telling unpack how many characters (or other data types) to read in. Maybe
>this is a Perl bug?
Nope, it's not a Perl bug. Just think of it this way: your original
code is basically equivalent to this:
@temp = unpack( "C11 C C18", $binary_data );
( @array1, $value1, @array2 ) = @temp;
Or, it's also basically equivalent to this:
@temp = unpack( "C30", $binary_data );
( @array1, $value1, @array2 ) = @temp;
In all cases, unpack() produces just a single list, and that list has
30 byte values in it.
- Logan
------------------------------
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 4900
**************************************