[32049] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3313 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 9 16:09:29 2011

Date: Wed, 9 Mar 2011 13:09:11 -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           Wed, 9 Mar 2011     Volume: 11 Number: 3313

Today's topics:
    Re: "getting" a website <bugbear@trim_papermule.co.uk_trim>
    Re: "getting" a website <Uno@example.invalid>
    Re: "getting" a website <Uno@example.invalid>
    Re: "getting" a website <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: "getting" a website <jimsgibson@gmail.com>
    Re: contexts (Randal L. Schwartz)
    Re: contexts <derykus@gmail.com>
    Re: FAQ 4.56 How do I merge two hashes? <derykus@gmail.com>
    Re: FAQ 4.56 How do I merge two hashes? <derykus@gmail.com>
    Re: how to extract the string part between the two mark <Beno.R@gmail.com>
    Re: how to extract the string part between the two mark <smallpond@juno.com>
        how to remove the string part between the two marks <Beno.R@gmail.com>
    Re: how to remove the string part between the two marks <NoSpamPleaseButThisIsValid3@gmx.net>
    Re: Variable length array of arrays into tree structure <bugbear@trim_papermule.co.uk_trim>
    Re: Variable length array of arrays into tree structure <cartercc@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 09 Mar 2011 13:23:26 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: "getting" a website
Message-Id: <CdWdne4DJ8_T4urQnZ2dnUVZ8kmdnZ2d@brightview.co.uk>

Uno wrote:
> My family owns this website, and I serve as an agent in its behalf.
>
> http://germanresistance.com/
>
> I have the _Perl Cookbook_, but have never actually gone and taken
> somebody's website before. I can assure you that the law is on my side
> here, unless it isn't because Barack has pointy ears.
>
> The guys I'm taking it from have to answer to the fbi and the local fuzz.
>
> Looking for tips as I do this with or without you.

Well, perl's great and all that, but there's a well know, and free tool
specifically designed to do this:

http://www.gnu.org/software/wget/manual/html_node/Recursive-Download.html#Recursive-Download

  BugBear


------------------------------

Date: Wed, 09 Mar 2011 12:12:37 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8tq1p6F2piU1@mid.individual.net>

On 03/08/2011 08:32 PM, Keith Keller wrote:
> On 2011-03-09, Uno<Uno@example.invalid>  wrote:
>>
>> q1) What's best way to serialize a website with perl?
>
> I'm going to take a WAG that you want to download as much as possible
> using GETs (ftp will be better, since you mentioned that you're trying
> to get it).  You will probably want to look at wget's recursive
> retrieval options.  If you later need to parse and modify the HTML, then
> as Jurgen suggested you should use the various HTML parsers available
> (e.g., HTML::Parser, HTML::TreeBuilder).
>
> If that's wrong then you need to explain exactly what "serializing" a
> website means.

By "serialize," I mean have a faithful representation of both the 
directories and the files.
>
>> q2) What things don't get gotten with get?
>
> Anything dynamic, e.g., a backend database, scripts, flat files
> generated dynamically, SSI directives (do people still use those?),
> probably lots more.
>
> If you get ftp access, you could use the Net::FTP module to retrieve
> files (or use a tool like ncftpget).

Ok, thx, keith.  I don't want to let this guy know what I'm doing, and I 
just have to hope that he doesn't notice all the attention that has 
recently occurred to pdf docs about how Dietrich Bonhoeffer can be 
shoe-horned into the parochial, regressive, dyspeptic notions of the 
Lutheran Church--Missouri Synod.

Isn't there a usenet group that discusses legality, property rights, 
criminal behavior in a web context?
-- 
Uno


------------------------------

Date: Wed, 09 Mar 2011 12:42:52 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8tq3htFg9iU1@mid.individual.net>

On 03/09/2011 06:23 AM, bugbear wrote:

> Well, perl's great and all that, but there's a well know, and free tool
> specifically designed to do this:
>
> http://www.gnu.org/software/wget/manual/html_node/Recursive-Download.html#Recursive-Download

Bugbear, I'm in shock, in a good way.  This is something that would 
never happen to a windows user:

wget -rH -Dgermanresistance.com http://germanresistance.com >text1

$ wget -rH -Dgermanresistance.com http://germanresistance.com >text1
--2011-03-09 12:23:04--  http://germanresistance.com/
Resolving germanresistance.com... 74.208.40.60
Connecting to germanresistance.com|74.208.40.60|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `germanresistance.com/index.html'

     [ <=>                                   ] 7,755       38.0K/s   in 
0.2s

2011-03-09 12:23:05 (38.0 KB/s) - `germanresistance.com/index.html' 
saved [7755]

Loading robots.txt; please ignore errors.
--2011-03-09 12:23:05--  http://germanresistance.com/robots.txt
Connecting to germanresistance.com|74.208.40.60|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: `germanresistance.com/robots.txt'



 ... [big snip]


2011-03-09 12:23:23 (27.5 KB/s) - 
`germanresistance.com/contact-us/feed/index.html' saved [708]

FINISHED --2011-03-09 12:23:23--
Downloaded: 41 files, 295K in 7.5s (39.0 KB/s)
$


I told my uncle that it would take me 50 seconds.  Nice to know I've 
still got the touch.  They've made him believe that this website is some 
unbelievable, irreplaceable thing.  They also said it was in Dan's basement.

Out of curiosity, can somebody tell where this server is, physically?

I wasn't expecting any of this to happen, but when I saw that this 
script was saving filings for me in a directory structure, then I set 
about finding it, and they put it right in one's home:
$ pwd
/home/dan/germanresistance.com
$ ls -l
total 40
drwxr-xr-x 3 dan dan 4096 2011-03-09 12:23 contact-us
drwxr-xr-x 3 dan dan 4096 2011-03-09 12:23 home
-rw-r--r-- 1 dan dan 7755 2011-03-09 12:23 index.html
drwxr-xr-x 2 dan dan 4096 2011-03-09 12:23 index-of-papers
-rw-r--r-- 1 dan dan   24 2011-03-09 12:23 robots.txt
drwxr-xr-x 5 dan dan 4096 2011-03-09 12:23 wp-content
drwxr-xr-x 3 dan dan 4096 2011-03-09 12:23 wp-includes
-rw-r--r-- 1 dan dan   42 2011-03-09 12:23 xmlrpc.php
-rw-r--r-- 1 dan dan  858 2011-03-09 12:23 xmlrpc.php?rsd
$ ls *
index.html  robots.txt  xmlrpc.php  xmlrpc.php?rsd

contact-us:
feed  index.html

home:
feed

index-of-papers:
index.html

wp-content:
plugins  themes  uploads

wp-includes:
js  wlwmanifest.xml
$

Had only a few minutes for this today and feel like I hit a home run. 
Now to get my truck back from the shop and pay the bill.:(
-- 
Uno




------------------------------

Date: Wed, 9 Mar 2011 12:02:58 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: "getting" a website
Message-Id: <i03l48x8du.ln2@goaway.wombat.san-francisco.ca.us>

On 2011-03-09, Uno <Uno@example.invalid> wrote:
>
> wget -rH -Dgermanresistance.com http://germanresistance.com >text1

Since you're using wget, this is offtopic for comp.lang.perl.misc.

[snip]

--keith


-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



------------------------------

Date: Wed, 09 Mar 2011 13:02:40 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: "getting" a website
Message-Id: <090320111302407945%jimsgibson@gmail.com>

In article <8tq3htFg9iU1@mid.individual.net>, Uno <Uno@example.invalid>
wrote:

> Out of curiosity, can somebody tell where this server is, physically?

Wayne, Pennsylvania?

<http://www.melissadata.com/lookups/iplocation.asp?ipaddress=74.208.40.6
0>
<http://www.geobytes.com/IpLocator.htm?GetLocation>
<http://www.geobytes.com/IpLocator.htm?GetLocation>

Please limit your posts to discussions of Perl. Thank you.

-- 
Jim Gibson


------------------------------

Date: Wed, 09 Mar 2011 08:28:07 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: contexts
Message-Id: <86sjuwdzs8.fsf@red.stonehenge.com>

>>>>> "Charlton" == Charlton Wilbur <cwilbur@chromatico.net> writes:

Charlton> Responding to any criticism -- especially reasonable criticisms -- of
Charlton> your favorite programming language as if it were a racial slur is the
Charlton> sort of thing that rabid fanboys do -- as is the implication that
Charlton> because I don't think Perl is flawless and perfect that I should go off
Charlton> and use something else.  You are, or at least should be, better than
Charlton> that.

You're putting words into my mouth.  I was talking only about the
extreme case.

*Reasonable* criticism is fair game.

Accusing Perl of "not being like my favorite language X, and that's a
bad thing" isn't.  Since Perl isn't X.

If you want to criticize Perl, you must also keep Perl's well-stated
goals in mind.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


------------------------------

Date: Wed, 9 Mar 2011 11:20:14 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: contexts
Message-Id: <8b8f1184-840a-41dc-9525-ee045e9e20b8@a11g2000pri.googlegroups.com>

On Mar 8, 2:48=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2011-03-08 14:47, Randal L. Schwartz <mer...@stonehenge.com> wrote:
>
> >>>>>> "Charlton" =3D=3D Charlton Wilbur <cwil...@chromatico.net> writes:
>
> ...
> Well I'm rarely surprised by Perl, too. But then I've now used it for 16
> years (and discussed it on Usenet for nearly as long), so it shouldn't.
> But there are still some aspects of the language which I do not find
> intuitive. For example (since we were talking about references)
> autovivification. Referencing $x->[0][0] automatically creates $x->[0]
> as a reference to an empty array, but @{ $x->[0] } throws an exception.
> Why? Both cases seem almost exactly analogous to me.
>

Hm, both of the cases below just throw warnings
and the latter warning is more explicit. However,
an anonymous array does get created:


  perl   -wle "print $x->[0][0],'foo'"
  Name "main::x" used only once: possible typo at -e line 1.
  Use of uninitialized value in print at -e line 1.
  foo

  perl   -wle "print @{$x->[0]},'foo'"
  Name "main::x" used only once: possible typo at -e line 1.
  Use of uninitialized value in array dereference at -e line 1.
  foo

  perl -MO=3DConcise,-exec  -wle "print @{$x->[0]},'foo'"
  Name "main::x" used only once: possible typo at -e line 1.
  1  <0> enter
  2  <;> nextstate(main 2 -e:1) v:{
  3  <0> pushmark s
  4  <#> gv[*x] s
  5  <1> rv2sv sKM/DREFAV,1
  6  <1> rv2av[t2] sKR/1
  7  <$> const[IV 0] s
  8  <2> aelem sK/2
  9  <1> rv2av[t3] lK/1
  a  <$> const[PV "foo"] s
  b  <@> print vK
  c  <@> leave[1 ref] vKP/REFC
  -e syntax OK

--
Charles DeRykus



------------------------------

Date: Wed, 9 Mar 2011 12:33:30 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: FAQ 4.56 How do I merge two hashes?
Message-Id: <4a334546-389a-466c-ac37-d50193c359e3@a11g2000pri.googlegroups.com>

On Mar 9, 9:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:
> This is an excerpt from the latest version perlfaq4.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 4.56: How do I merge two hashes?
>
> =A0 =A0 (contributed by brian d foy)
>
> =A0 =A0 Before you decide to merge two hashes, you have to decide what to=
 do if
> =A0 =A0 both hashes contain keys that are the same and if you want to lea=
ve the
> =A0 =A0 original hashes as they were.
>
> =A0 =A0 If you want to preserve the original hashes, copy one hash (%hash=
1) to a
> =A0 =A0 new hash (%new_hash), then add the keys from the other hash (%has=
h2 to
> =A0 =A0 the new hash. Checking that the key already exists in %new_hash g=
ives
> =A0 =A0 you a chance to decide what to do with the duplicates:
>
> =A0 =A0 =A0 =A0 =A0 =A0 my %new_hash =3D %hash1; # make a copy; leave %ha=
sh1 alone
>
> =A0 =A0 =A0 =A0 =A0 =A0 foreach my $key2 ( keys %hash2 )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if( exists $new_hash{$key2} )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn "Key [$key2]=
 is in both hashes!";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # handle the dupl=
icate (perhaps only warning)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $new_hash{$key2} =
=3D $hash2{$key2};
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> =A0 =A0 If you don't want to create a new hash, you can still use this lo=
oping
> =A0 =A0 technique; just change the %new_hash to %hash1.
>
> =A0 =A0 =A0 =A0 =A0 =A0 foreach my $key2 ( keys %hash2 )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if( exists $hash1{$key2} )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn "Key [$key2]=
 is in both hashes!";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # handle the dupl=
icate (perhaps only warning)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $hash1{$key2} =3D=
 $hash2{$key2};
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> =A0 =A0 If you don't care that one hash overwrites keys and values from t=
he
> =A0 =A0 other, you could just use a hash slice to add one hash to another=
 . In
> =A0 =A0 this case, values from %hash2 replace values from %hash1 when the=
y have
> =A0 =A0 keys in common:
>
> =A0 =A0 =A0 =A0 =A0 =A0 @hash1{ keys %hash2 } =3D values %hash2;

Or even shorter:

            %hash1 =3D ( %hash1, %hash2 );

--
Charles DeRykus


------------------------------

Date: Wed, 9 Mar 2011 12:39:24 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: FAQ 4.56 How do I merge two hashes?
Message-Id: <0f5fda1f-d950-40c9-80d4-98c45e6bae53@f15g2000pro.googlegroups.com>

On Mar 9, 12:33=A0pm, "C.DeRykus" <dery...@gmail.com> wrote:
> On Mar 9, 9:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:
>
>
>
> > This is an excerpt from the latest version perlfaq4.pod, which
> > comes with the standard Perl distribution. These postings aim to
> > reduce the number of repeated questions as well as allow the community
> > to review and update the answers. The latest version of the complete
> > perlfaq is athttp://faq.perl.org.
>
> > --------------------------------------------------------------------
>
> > 4.56: How do I merge two hashes?
>
> > =A0 =A0 (contributed by brian d foy)
>
> > =A0 =A0 Before you decide to merge two hashes, you have to decide what =
to do if
> > =A0 =A0 both hashes contain keys that are the same and if you want to l=
eave the
> > =A0 =A0 original hashes as they were.
>
> > =A0 =A0 If you want to preserve the original hashes, copy one hash (%ha=
sh1) to a
> > =A0 =A0 new hash (%new_hash), then add the keys from the other hash (%h=
ash2 to
> > =A0 =A0 the new hash. Checking that the key already exists in %new_hash=
 gives
> > =A0 =A0 you a chance to decide what to do with the duplicates:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 my %new_hash =3D %hash1; # make a copy; leave %=
hash1 alone
>
> > =A0 =A0 =A0 =A0 =A0 =A0 foreach my $key2 ( keys %hash2 )
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if( exists $new_hash{$key2} )
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn "Key [$key=
2] is in both hashes!";
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # handle the du=
plicate (perhaps only warning)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $new_hash{$key2=
} =3D $hash2{$key2};
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 If you don't want to create a new hash, you can still use this =
looping
> > =A0 =A0 technique; just change the %new_hash to %hash1.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 foreach my $key2 ( keys %hash2 )
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if( exists $hash1{$key2} )
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn "Key [$key=
2] is in both hashes!";
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # handle the du=
plicate (perhaps only warning)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $hash1{$key2} =
=3D $hash2{$key2};
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 If you don't care that one hash overwrites keys and values from=
 the
> > =A0 =A0 other, you could just use a hash slice to add one hash to anoth=
er. In
> > =A0 =A0 this case, values from %hash2 replace values from %hash1 when t=
hey have
> > =A0 =A0 keys in common:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 @hash1{ keys %hash2 } =3D values %hash2;
>
> Or even shorter:
>
> =A0 =A0 =A0 =A0 =A0 =A0 %hash1 =3D ( %hash1, %hash2 );
>

efficiency may be an issue though..

--
Charles DeRykus



------------------------------

Date: Wed, 9 Mar 2011 13:32:00 +0100
From: "Beno" <Beno.R@gmail.com>
Subject: Re: how to extract the string part between the two marks
Message-Id: <il7rvo$e69$1@localhost.localdomain>

Not to remove, I need to extract the tekst 12:30

> how to remove the string part between the two marks
> for example
> from string "<DIV> </ DIV> <SPAN ID=TIME> 12:30 </ SPAN> <SOME TEXT>"
> extract the text "12:30"
>
> I succeeded so I made the first split the string with the word
> <SPAN ID=TIME> then again split the string with the word </ SPAN>
>
> works but is complicated:
>
> $ string = "<DIV> </ DIV> <SPAN ID=TIME> 12:30 </ SPAN> <SOME TEXT>";
> @ part1 = split (/ <SPAN ID=TIME> /, $ string);
> @ part2 = split (/ <\ / SPAN> /, $ part1 [0]);
> print part2 [0];
>
> I know that there is an easier way in Perl, but how?
>
> Please help.
> Thanks.
>
> Beno
> 




------------------------------

Date: Wed, 9 Mar 2011 08:24:20 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: how to extract the string part between the two marks
Message-Id: <ff86b6d7-53d4-4075-995a-b1b861f3ff15@r4g2000prm.googlegroups.com>

On Mar 9, 7:32=A0am, "Beno" <Ben...@gmail.com> wrote:
> Not to remove, I need to extract the tekst 12:30
>
> > how to remove the string part between the two marks
> > for example
> > from string "<DIV> </ DIV> <SPAN ID=3DTIME> 12:30 </ SPAN> <SOME TEXT>"
> > extract the text "12:30"
>
> > I succeeded so I made the first split the string with the word
> > <SPAN ID=3DTIME> then again split the string with the word </ SPAN>
>
> > works but is complicated:
>
> > $ string =3D "<DIV> </ DIV> <SPAN ID=3DTIME> 12:30 </ SPAN> <SOME TEXT>=
";
> > @ part1 =3D split (/ <SPAN ID=3DTIME> /, $ string);
> > @ part2 =3D split (/ <\ / SPAN> /, $ part1 [0]);
> > print part2 [0];
>
> > I know that there is an easier way in Perl, but how?
>

$h =3D "<DIV> </ DIV> <SPAN ID=3DTIME> 12:30 </ SPAN> <SOME TEXT>";
$h =3D~ / \<SPAN ID=3DTIME> (.*) \<\/ SPAN> /;
print $1;

12:30



------------------------------

Date: Wed, 9 Mar 2011 13:30:08 +0100
From: "Beno" <Beno.R@gmail.com>
Subject: how to remove the string part between the two marks
Message-Id: <il7rs7$e5c$1@localhost.localdomain>

how to remove the string part between the two marks
for example
from string "<DIV> </ DIV> <SPAN ID=TIME> 12:30 </ SPAN> <SOME TEXT>"
extract the text "12:30"

I succeeded so I made the first split the string with the word
<SPAN ID=TIME> then again split the string with the word </ SPAN>

works but is complicated:

$ string = "<DIV> </ DIV> <SPAN ID=TIME> 12:30 </ SPAN> <SOME TEXT>";
@ part1 = split (/ <SPAN ID=TIME> /, $ string);
@ part2 = split (/ <\ / SPAN> /, $ part1 [0]);
print part2 [0];

I know that there is an easier way in Perl, but how?

Please help.
Thanks.

Beno 




------------------------------

Date: Wed, 09 Mar 2011 13:50:55 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: how to remove the string part between the two marks
Message-Id: <4d7777af$0$6877$9b4e6d93@newsspool2.arcor-online.net>

On 09.03.2011 13:30, Beno wrote:
> how to remove the string part between the two marks
> for example
> from string "<DIV> </ DIV> <SPAN ID=TIME> 12:30 </ SPAN> <SOME TEXT>"
> extract the text "12:30"
> 
> I succeeded so I made the first split the string with the word
> <SPAN ID=TIME> then again split the string with the word </ SPAN>

This looks like html.

perldoc -q html

- Wolf


------------------------------

Date: Wed, 09 Mar 2011 09:27:28 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <b5ednUSDD_6d1erQnZ2dnUVZ8v-dnZ2d@brightview.co.uk>

WhoDare wrote:
>> push ( @{ $data{ 'Sessions' }{ 'NOC-CO' }{ 'AFC' }{ 'ADMSND70AFC.01' }
>> }, '172.16.22.34' );
>
> The problem I am having is that I'm dealing with variable lengths.
> Pushing into the above array is 5 elements.  There are other elements
> that are 3 elements long, 4 elements long, etc.  So it's variable.

So instead of a multi-key one-hit, simply iterate, a level at a time.

  BugBear



------------------------------

Date: Wed, 9 Mar 2011 06:22:44 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <233a3a01-17cb-4747-852a-469843bcbe3e@t15g2000prt.googlegroups.com>

On Mar 8, 11:31=A0am, Don Pich <dp...@polartel.com> wrote:
> I have generated an array of arrays from a csv file. =A0Here is an exampl=
e
> of the data stored in the array (note: =A0the ' - ' are just element
> dividers and not actual elements. =A0They are just text).
>
> ADMSND70AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.34
> ARTHND16AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.26
> CAVWND48AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.6

In general, using a hash for this kind of task is a lot easier. When
you iterate through your file, destructure each line and stuff the
data elements into a hash, like this:

my %sessions;
while (<DATA>)
{
  next unless /\w/;
  chomp;
  my ($key, $ses, $noc, $afc, $ip) =3D split(/ - /, $_);
  $sessions{$noc}{$afc}{$ip} =3D $ip if $ses =3D~ /sessions/i;
}

Of course, you can have multiple hashes, and sort your data however
you like. Once you have your data in memory, it's trivial to print
your hash, like this:

foreach my $k1 (keys %sessions)
{
  print "$k1 =3D>\n";
  foreach my $k2 (keys %{$sessions{$k1}})
  {
    print "    $k2 =3D>\n"
    foreach my $k3 (keys %{$sessions{$k1}{$k2}})
    {
      print "        $k3 =3D> $sessions{$k1}{$k2}{$k3}\n";
    }
  }
}

You can also use the increment operator (++) to accumulate the number
of times each element appears, which is sometimes useful. Often, I
will store the entire line as a string as the value of the bottom hash
element, which makes it easy to get at the data after it's been sliced
and diced in various ways.

I haven't tested the above code, it probably contains errors, but you
get the idea.

CC.


------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3313
***************************************


home help back first fref pref prev next nref lref last post