[25674] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7915 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 29 12:57:19 2005

Date: Tue, 29 Mar 2005 09:57:07 -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           Tue, 29 Mar 2005     Volume: 10 Number: 7915

Today's topics:
    Re: LWP Doesn't Seem To Save Cookies: <hal@thresholddigital.com>
    Re: LWP Doesn't Seem To Save Cookies: <noreply@gunnar.cc>
    Re: LWP Doesn't Seem To Save Cookies: <usenet@vyznev.invalid>
    Re: LWP: Any Easy Way to Use Relative Links? <bart.lateur@pandora.be>
    Re: memory leak in 5.8.2??? <joe.cipale@radisys.com>
        Need syntax/small footprint help <robic0@yahoo.com>
    Re: Need syntax/small footprint help <nobull@mail.com>
    Re: Need syntax/small footprint help <nobull@mail.com>
    Re: Need syntax/small footprint help robic0@yahoo.com
    Re: Need syntax/small footprint help robic0@yahoo.com
    Re: Net::FTP (bala)
        newbie help - finding all substrings with index? <brettaw@NO_spam_gmail.com>
    Re: newbie help - finding all substrings with index? <1usa@llenroc.ude.invalid>
    Re: newbie help - finding all substrings with index? <nobull@mail.com>
    Re: newbie help - finding all substrings with index? <nobull@mail.com>
    Re: newbie question <do-not-use@invalid.net>
        newbie question: display xmlfile (JanVDV)
    Re: newbie question: display xmlfile <nobull@mail.com>
    Re: newbie question: display xmlfile <see.sig@rochester.rr.com>
    Re: newbie question: display xmlfile <robic0@yahoo.com>
    Re: newbie question: display xmlfile <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 Mar 2005 03:26:28 -0500
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: LWP Doesn't Seem To Save Cookies:
Message-Id: <xOKdncm2LbSptdzfRVn-2Q@comcast.com>

Todd W wrote:

> 
> "Hal Vaughan" <hal@thresholddigital.com> wrote in message
> news:2Y-dnU1DnpqllNzfRVn-jA@comcast.com...
>> I'm trying to write a scraper for a website that uses cookies.  The short
> of
>> it is that I keep getting their "You have to set your browser to allow
>> cookies" message.  The code for the full scraper is a bit much, so here
> are
>> the relevant sections:
>>
> <snip />
> 
> I've had a lot of sucess using LWP to scrape web pages, for instance I
> have a neat program that shows me all my bank account balances on my web
> enabled cell phone, but Ive had some trouble getting LWP to scrape some
> pages that required cookies also.
> 
> Heres my code:
> 
> [trwww[at]waveright temp]$ perl -MWWW::Mechanize::Shell -e 'shell'
>>get https://www.setsivr.odjfs.state.oh.us/welcome.asp
> Retrieving https://www.setsivr.odjfs.state.oh.us/welcome.asp(200)
> https://www.setsivr.odjfs.state.oh.us/cookieerror.htm>
> 
> If the client and the server were doing everything according to
> specification, this would work.
> 
> I get the same problem with lynx, and another poster on perl.libwww
> verified my issue, and also got the same error using a python http
> library.
> 
> Heres the archive of my thread:
> 
>
http://groups-beta.google.com/group/perl.libwww/browse_thread/thread/38d09ffd6ff2f4fd

I checked the thread, and I've gone back over the pages I downloaded.  I
wasn't clear (I think I mentioned it in my first post) about how cookies
are normally handled, and had not looked closely at the files (since I
figured that was not likely the problem).  It turns out that the cookie IS
being set in Javascript, which I suspected, but didn't realize this is a
problem.  I wrote out a routine that scanned the page, grabbed the cookie,
and set it manually with $cookie_jar->set_cookie(), and it looks like it is
set properly (it includes the domain and path setting, as well).  However,
even after setting the cookie manually, I either get "no cookie" messages,
or trying to load any page after the login gives me the login page again
(which I noticed happens in Firefox if I try to paste in a link to a page
after the login page when I'm not logged in).  (I also looked at the
cookies in Firefox to see if it looked like the same ones I was getting in
Perl, and they seem the same except for the session ID number.)

So I've found a way to set the cookie by hand, but the server I'm trying to
read from doesn't seem to see the cookie is set.  Is there something I need
to do, other than setting a cookie, to make sure the server I'm connecting
to knows the cookie is set?

This is not an area I'm an expert in, and it's frustrating because I need to
get this done, so I'm low on sleep, and trying to put together a lot more
pieces than I expected in this.  I didn't know, when I sent a page request
to a server, that the server could actually read the cookie with the
request, I thought cookies were only used by client side Java, but the fact
that the server won't send me the right pages without the cookie seems to
say the server can read the cookie.  Is that right?  If so, how do I make
sure the server gets the cookie?

Thanks for any help on this!

Hal


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

Date: Wed, 23 Mar 2005 10:00:00 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: LWP Doesn't Seem To Save Cookies:
Message-Id: <3acpraF68vlo4U1@individual.net>

Hal Vaughan wrote:
> I thought that LWP automatically took the cookies out of the page (I also
> thought cookies were in the header, the one here is set with
> document.cookie="doc cookie" within the document), and stored them in the
> cookie jar automatically.  That doesn't seem to be happening.  I've been
> reading the perldocs, but I can't see anything in the response object that
> allows me to check the page for cookies, so I can do it myself.

This thread with a similar topic might contain something useful:

http://groups-beta.google.com/group/comp.lang.perl.misc/browse_frm/thread/f8f4b9ef0d73a11d

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 28 Mar 2005 11:59:12 +0300
From: Ilmari Karonen <usenet@vyznev.invalid>
Subject: Re: LWP Doesn't Seem To Save Cookies:
Message-Id: <slrnd4fhr0.2op.usenet@boojum.home.vyznev.net>

Hal Vaughan <hal@thresholddigital.com> wrote on 2005-03-23:
 [snip]
> even after setting the cookie manually, I either get "no cookie" messages,
> or trying to load any page after the login gives me the login page again
> (which I noticed happens in Firefox if I try to paste in a link to a page
> after the login page when I'm not logged in).

It looks like the server might be checking the Referer header.  You
may want to try to include one in every request you make, like this:

  my $res = $ua->get($url, Referer => $ref);

where $ref is the URL of the page you got $url from.  (It might be
enough just to give any URL from the same site, but then again, it
might not.)

A server paranoid enough to do things like that may also be checking
User-Agent headers, so if you're not doing that already, I'd suggest
setting yours to imitate some common browser, like this:

  $ua->agent('Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)');

-- 
Ilmari Karonen
To reply by e-mail, please replace ".invalid" with ".net" in address.


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

Date: Wed, 23 Mar 2005 09:31:10 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: LWP: Any Easy Way to Use Relative Links?
Message-Id: <apd2419qieab53tk2sfhq0fnm32lr154qm@4ax.com>

Jay Tilton wrote:

>HTML::LinkExtor is your one-stop answer.  It can snatch links from HTML
>better than your regex can, and it can return all links in a
>fully-qualified form if given a base URL.

See also HTML::SimpleLinkExtor for a similar module with a (maybe)
simpler API.

-- 
	Bart.


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

Date: 28 Mar 2005 09:46:56 -0800
From: "joe.cipale@radisys.com" <joe.cipale@radisys.com>
Subject: Re: memory leak in 5.8.2???
Message-Id: <1112032016.012376.276380@f14g2000cwb.googlegroups.com>

To all who replied,

Thanks for your advice. It turns out their was a code condition that
was not being performed properly based on a decision tree I had
implemented. The crummy thing was it took 3 of us nearly a week to find
it.

The offending code has been removed and shelved for the time being,
pending a design rewwork.

Joe



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

Date: 26 Mar 2005 12:24:11 -0800
From: "robic0@yahoo.com" <robic0@yahoo.com>
Subject: Need syntax/small footprint help
Message-Id: <1111868651.371292.24210@g14g2000cwa.googlegroups.com>

Hello, last month I wrote a rather large 10,000 line program that
parses xml (expat). The data is read into compound structures
then analyzed later. Below is one of the subroutines. I would like
to make it smaller so that its easier to read and understand and
also make the regular expressions less complicated for performance.
Any ideas?

---------------------------
sub eCHK_RegDel       ## -- checks Redundant Regkey Delete // Regkey
exists --
{
	my ($details) = @_;
	return 1 if (@{$details} == 0);
	my @regdel = ();

	for (@$details) {
		my $aref = $_->[0];
		push (@regdel, $aref) if ($aref->[5] eq $REGISTRY && $aref->[6] eq
$DELETE);
	}
	if (@regdel)
	{
		## check that KeyName exists
		for (@regdel) {
			my $aref = $_;
			next if (exists ($aref->[4]{$KEYNAME}) &&
length($aref->[4]{$KEYNAME}) > 0);
			# log error
			## 0701 -- test 07,01
			ReportItem ('E', $CLOGINFO, $CERRLOG, '0701', glicn($aref), (0,0),
'', $XML_File, 1,0,1);
		}
		## check redundant regkey deletes
		my $first_kname = '';
		my $first_vname_exists = 0;
		my $aref_first = undef;

		my @regx_esc_codes = ( "\\", '/', '(', ')', '[', ']', '?', '|',
                                        '+', '.', '*', '$', '^', '{',
'}', '@' );
		for (@regdel)
		{
			my $aref = $_;
			next if (!(exists ($aref->[4]{$KEYNAME}) &&
length($aref->[4]{$KEYNAME}) > 0));
			my $kname = $aref->[4]{$KEYNAME};
			my $vname = '';
			my $kv = 'key (branch)';
			if (exists ($aref->[4]{$VALUENAME})) {
				if (length($aref->[4]{$VALUENAME}) > 0) {
					$vname = $aref->[4]{$VALUENAME};
					# strip leading spaces
					while ($vname =~ s/^ //) {}
				}
				$kv = 'value';
			}
			for (@regx_esc_codes)
			{
				my $tc = $_;
				my $xx = "\$kname =~ s/\\$tc/\\\\\\$tc/g;";     # code template for
regex
				eval $xx;
				#print "$xx\n";
			}
			$kname = $kname."\\\\";
			my $fnd = 0;
			# -- #
			my $ctmpl =  "if (\$kname =~ /^$first_kname/i) {\$fnd = 1;}";  #
code template for first key name
			eval $ctmpl;
			# -- #
			#print
"-------------\n$fnd,$ctmpl\nkname=$kname\n--------------\n\n";
			#print
"-------------\n$fnd,$ctmpl\nkname=$kname\nfirst=$first_kname\n--------------\n\n";
			if ($@) {
				## Check the $ctmpl, get the control code, log this error as a code
issue.
				## This shouldn't happen ... the compiler will show the escape
char, add
				## the char to "@regx_esc_codes", now its fixed!
				$@ =~ s/^[\x20\n\t]+//; $@ =~ s/[\x20\n\t]+$//;
				## 0702 -- test 07,02
				ReportItem ('E', $CLOGINFO, $CERRLOG, '0702', (0,0,0,0), $@,
$XML_File, 1,0,1);
			}
			if ((!$fnd || length ($first_kname) == 0))
			{
				# because of sort,the first non valuename
				# will always be in the new keyname action

				$first_kname = uc($kname);
				for (@regx_esc_codes)
				{
					my $tc = $_;
					my $xx = "\$first_kname =~ s/\\$tc/\\\\\\$tc/g;";     # code
template for regex
					eval $xx;
				}
				$aref_first = $aref;
				if (length ($vname) > 0) {$first_vname_exists = 1} else {
$first_vname_exists = 0}
				next;
			}
			next if ($first_vname_exists);
			if (length($vname) == 0) {
				if ($fnd) {
					# log error, this sub-key is already being deleted
					## 0703 -- test 07,03
					ReportItem ('E', $CLOGINFO, $CERRLOG, '0703', glicn($aref),
glicn($aref_first), '', $XML_File, 1,0,1);
				}
				next;
			}
			# log error, the key for this value is already being deleted
			## 0704 -- test 07,04
			ReportItem ('E', $CLOGINFO, $CERRLOG, '0704', glicn($aref),
glicn($aref_first), '', $XML_File, 1,0,1);
		}
	}
}
-----------------------------



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

Date: Sun, 27 Mar 2005 10:28:12 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need syntax/small footprint help
Message-Id: <d261gv$jek$1@sun3.bham.ac.uk>



robic0@yahoo.com wrote:

> Hello, last month I wrote a rather large 10,000 line program that
> parses xml (expat). The data is read into compound structures
> then analyzed later. Below is one of the subroutines. I would like
> to make it smaller so that its easier to read and understand and
> also make the regular expressions less complicated for performance.
> Any ideas?
> 
> ---------------------------
> sub eCHK_RegDel       ## -- checks Redundant Regkey Delete // Regkey
> exists --
> {
> 	my ($details) = @_;
> 	return 1 if (@{$details} == 0);

   return 1 unless @$details;

But actually this is, I think, redundant.  There is no point since if 
@$details is empty so will @regdel so nothing will happen anyhow.

Why are you returning 1? You don't seem to be bothering about the 
returning anything in other situations so I infer that nothing is 
considering the return value of eCHK_RegDel.

> 	my @regdel = ();
> 	for (@$details) {
> 		my $aref = $_->[0];
> 		push (@regdel, $aref) if ($aref->[5] eq $REGISTRY && $aref->[6] eq
> $DELETE);
> 	}

my @regdel =
    grep { $_->[5] eq $REGISTRY && $_->[6] eq $DELETE )
    map { $_->[0] } @$details;


> 	if (@regdel)
> 	{

Again this is redundant.  "If the next line would do nothing then don't 
do it".  But if the next line would do nothing there's no cost in doing 
it anyhow.

> 		## check that KeyName exists
> 		for (@regdel) {
> 			my $aref = $_;

You don't need the value in $_ so simply:

  		for my $aref (@regdel) {

> 			next if (exists ($aref->[4]{$KEYNAME}) &&
> length($aref->[4]{$KEYNAME}) > 0);

You mean defined() not exists().

length() can never be negative so >0 is redundant.

There could be a case for simply using no warnings 'uninitialized' here.

> 			# log error
> 			## 0701 -- test 07,01
> 			ReportItem ('E', $CLOGINFO, $CERRLOG, '0701', glicn($aref), (0,0),
> '', $XML_File, 1,0,1);
> 		}
> 		## check redundant regkey deletes
> 		my $first_kname = '';
> 		my $first_vname_exists = 0;
> 		my $aref_first = undef;
> 
> 		my @regx_esc_codes = ( "\\", '/', '(', ')', '[', ']', '?', '|',
>                                         '+', '.', '*', '$', '^', '{',
> '}', '@' );

This is invarient and should be taken outside the loop or maybe even 
outside the subroutine.  But you don't need it at all probably.

> 		for (@regdel)
> 		{
> 			my $aref = $_;
> 			next if (!(exists ($aref->[4]{$KEYNAME}) &&
> length($aref->[4]{$KEYNAME}) > 0));

Why the second loop?  Why not a do it in a single pass?

> 			my $kname = $aref->[4]{$KEYNAME};
> 			my $vname = '';
> 			my $kv = 'key (branch)';
> 			if (exists ($aref->[4]{$VALUENAME})) {
> 				if (length($aref->[4]{$VALUENAME}) > 0) {
> 					$vname = $aref->[4]{$VALUENAME};
> 					# strip leading spaces
> 					while ($vname =~ s/^ //) {}

   s/^ +//;

> 				}
> 				$kv = 'value';
> 			}
> 			for (@regx_esc_codes)
> 			{
> 				my $tc = $_;
> 				my $xx = "\$kname =~ s/\\$tc/\\\\\\$tc/g;";     # code template for
> regex
> 				eval $xx;
> 				#print "$xx\n";
> 			}

Do not use eval unless there is a reason to do so.  The above is more simply

for my $tc (@regx_esc_codes) {
   $kname =~ s/(\Q$tc\E)/\\$1/g;
}

But I suspect you simply wanted

   $kname = quotemeta $kname;

But I'm guessing you wouldn't need to do anything if you got rid of some 
more of the pointless eval()s in your code.

All in all I think you are working way too. Hard.  I'll stop now with 
the line-by-line and go have another look at your code in its entirity. 
  Get back to you soon.



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

Date: Sun, 27 Mar 2005 16:27:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need syntax/small footprint help
Message-Id: <d26mis$8q$1@sun3.bham.ac.uk>



Brian McCauley wrote:

> All in all I think you are working way too hard.  I'll stop now with 
> the line-by-line and go have another look at your code in its entirity. 
>  Get back to you soon.

Below find an, untested but much simpler version.  I have not changed 
the alorithm just removed some of the tortuous obfuscations.

I've subsequently noticed what I presume is a flaw in the algorithm (but 
that's not Perl related so OT here).
Consider:

  { $KEYNAME => 'foo', $VALUENAME => 'bar' }
  { $KEYNAME => 'foo\blab' }
  { $KEYNAME => 'foo\blab', $VALUENAME => 'bar' }

I'm guessing the 3rd one above should be reported as redundant but won't be.

## -- checks Redundant Regkey Delete // Regkey exists --
sub eCHK_RegDel {
     my ($details) = @_;
     my ($first_kname,$first_vname_exists,$aref_first);
     for (@$details) {
	my $aref = $_->[0];
	next unless $aref->[5] eq $REGISTRY && $aref->[6] eq $DELETE;
	my $kname = $aref->[4]{$KEYNAME};

	# Can input data really contain $kname='' ?
	# if not then the check of length($kname) is redundant.

	unless ( defined($kname) && length($kname) ) {
	    # log error
	    ## 0701 -- test 07,01
	    ReportItem ('E', $CLOGINFO, $CERRLOG, '0701', glicn($aref), (0,0),
			'', $XML_File, 1,0,1);
	    next;
	}
	my $vname = $aref->[4]{$VALUENAME};

	# redunant surely - does input really contain $vname
	# with leading spaces or empty strings?
	if ( defined $vname ) {
	    $vname =~ s/^ +//;
	    undef $vname unless length $vname;
	}

	$kname .= "\\\\";
	unless ( $first_kname && $kname =~ /^\Q$first_kname/i ) {
	    # because of sort,the first non valuename
	    # will always be in the new keyname action

	    $first_kname = $kname;
	    $aref_first = $aref;
	    $first_vname_exists = defined($vname);
	    next;
	}
	next if $first_vname_exists;
	ReportItem ('E', $CLOGINFO, $CERRLOG,
		    defined($vname) ? '0703' : '0704',
		    glicn($aref), glicn($aref_first), '',
		    $XML_File, 1,0,1);
     }
}




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

Date: Mon, 28 Mar 2005 21:44:40 -0800
From: robic0@yahoo.com
Subject: Re: Need syntax/small footprint help
Message-Id: <tdqh419a1664v52sqb0dnfn8rtpeqtlj0b@4ax.com>

On Sun, 27 Mar 2005 16:27:35 +0000, Brian McCauley <nobull@mail.com>
wrote:

>
>
>Brian McCauley wrote:
>
>> All in all I think you are working way too hard.  I'll stop now with 
>> the line-by-line and go have another look at your code in its entirity. 
>>  Get back to you soon.
>
>Below find an, untested but much simpler version.  I have not changed 
>the alorithm just removed some of the tortuous obfuscations.
>
>I've subsequently noticed what I presume is a flaw in the algorithm (but 
>that's not Perl related so OT here).
>Consider:
>
>  { $KEYNAME => 'foo', $VALUENAME => 'bar' }
>  { $KEYNAME => 'foo\blab' }
>  { $KEYNAME => 'foo\blab', $VALUENAME => 'bar' }
>
>I'm guessing the 3rd one above should be reported as redundant but won't be.
>
>## -- checks Redundant Regkey Delete // Regkey exists --
>sub eCHK_RegDel {
>     my ($details) = @_;
>     my ($first_kname,$first_vname_exists,$aref_first);
>     for (@$details) {
>	my $aref = $_->[0];
>	next unless $aref->[5] eq $REGISTRY && $aref->[6] eq $DELETE;
>	my $kname = $aref->[4]{$KEYNAME};
>
>	# Can input data really contain $kname='' ?
>	# if not then the check of length($kname) is redundant.
>
>	unless ( defined($kname) && length($kname) ) {
>	    # log error
>	    ## 0701 -- test 07,01
>	    ReportItem ('E', $CLOGINFO, $CERRLOG, '0701', glicn($aref), (0,0),
>			'', $XML_File, 1,0,1);
>	    next;
>	}
>	my $vname = $aref->[4]{$VALUENAME};
>
>	# redunant surely - does input really contain $vname
>	# with leading spaces or empty strings?
>	if ( defined $vname ) {
>	    $vname =~ s/^ +//;
>	    undef $vname unless length $vname;
>	}
>
>	$kname .= "\\\\";
>	unless ( $first_kname && $kname =~ /^\Q$first_kname/i ) {
>	    # because of sort,the first non valuename
>	    # will always be in the new keyname action
>
>	    $first_kname = $kname;
>	    $aref_first = $aref;
>	    $first_vname_exists = defined($vname);
>	    next;
>	}
>	next if $first_vname_exists;
>	ReportItem ('E', $CLOGINFO, $CERRLOG,
>		    defined($vname) ? '0703' : '0704',
>		    glicn($aref), glicn($aref_first), '',
>		    $XML_File, 1,0,1);
>     }
>}
>

Hey man, thanks. This is just a followup test msg using Agent, lost
the google crap, now I can see mo better.
Yeah, you got some interresting stuff, I am going to correlate it with
the code once I set up everything. Some stuff you overlooked,
but some good stuff I have to check out. This is just a test
of Agent so I just in "check" mode for that. Obvious of interrest
is the extreme back slashing regx wise... I'll explain that too later.
Anyway thanks for the look Brian... be back to ya !!!

-RFC



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

Date: Mon, 28 Mar 2005 22:25:17 -0800
From: robic0@yahoo.com
Subject: Re: Need syntax/small footprint help
Message-Id: <sgrh41lqkrng38ksj4odbbiov9a5j4fjph@4ax.com>

On Mon, 28 Mar 2005 21:44:40 -0800, robic0@yahoo.com wrote:
>Hey man, thanks. This is just a followup test msg using Agent, lost
>the google crap, now I can see mo better.
>Yeah, you got some interresting stuff, I am going to correlate it with
>the code once I set up everything. Some stuff you overlooked,
>but some good stuff I have to check out. This is just a test
>of Agent so I just in "check" mode for that. Obvious of interrest
>is the extreme back slashing regx wise... I'll explain that too later.
>Anyway thanks for the look Brian... be back to ya !!!
>
>-RFC

I've got Forté Agent v 1.91, seems to be working good.
Most of the code in this program was written fast and diddn't 
have the luxury of detailed scrutiny and because of its size
and scope had to be written without the use of hidden
shortcuts or anything hard to read. For that reason it was
kept strictly on a C lang construct basis anything deeper
would have slowed down the write.

The "\\\\\\\\"  's et should be examined, along with what
this function is trying to do. This was a tough one to
program to say the least. Escape sequences in 
hard code are analogous in chemistry to being
"out of solution". You don't worry about "in solution"
unles its brought out to be operated on. There's a 
non-apparent unusual twist in this technique that
could be usefull maybe. Anyway, I've found alot
of other tricks doing this project. I think I will post
some of them on this thread. They need help too.
-RFC



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

Date: 26 Mar 2005 06:18:19 -0800
From: bbmk1234@yahoo.co.uk (bala)
Subject: Re: Net::FTP
Message-Id: <629b670a.0503260618.6e0474@posting.google.com>

Hi,

Does anyone know why Net::FTP does not support nmap?

I did check the documentation.

Is there any alternative?

Ta.


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

Date: Fri, 25 Mar 2005 22:52:08 +1100
From: kadau <brettaw@NO_spam_gmail.com>
Subject: newbie help - finding all substrings with index?
Message-Id: <MPG.1caea6738a31c9e8989680@news.tpg.com.au>

Hi :)

I hope this is an appropriate group to post in, my apologies if it is 
not. I would to to be able to read from a file and be able to locate all 
the instances of a substring within it, save it in an array, then print 
it out. I am fine with this except finding all the matches. Could anyone 
explain how to do this with index? Or is there some other way (please 
try to keep it simple if you can :)
Here is the text file ive been given

__

#Transaction code

S,M,L

#Sales commission

5:7:10

#Retail price items

*1<1002.00<
*2<125.00<
*3<61864.35<
*4<890876.99<
*5<9.99<

__

I want to locate & save to an array all lines begging with "*". I 
presume I will then be able to use split to get the raw prices out of 
the array (in between the "<").

Thanks to anyone who can help. 


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

Date: Fri, 25 Mar 2005 11:59:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: newbie help - finding all substrings with index?
Message-Id: <Xns96244719F4D9Easu1cornelledu@127.0.0.1>

kadau <brettaw@NO_spam_gmail.com> wrote in news:MPG.1caea6738a31c9e8989680
@news.tpg.com.au:

> it out. I am fine with this except finding all the matches. Could
> anyone explain how to do this with index? Or is there some other 
> way (please try to keep it simple if you can :)

What have you tried?

Have you read the documentation?

perldoc perlre
perldoc perlretut

Please consult the posting guidelines for this group for information on 
how to help others help you.

Sinan


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

Date: Fri, 25 Mar 2005 13:17:58 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie help - finding all substrings with index?
Message-Id: <d212n9$l34$1@sun3.bham.ac.uk>



kadau wrote:

> I hope this is an appropriate group to post in, my apologies if it is 
> not. I would to to be able to read from a file and be able to locate all 
> the instances of a substring within it, save it in an array, then print 
> it out. 

Are you sure that's _what_ you want to do and not _how_ you think you 
can do something?  Anyhow I think you are expressing what you want 
carefully.  In programming, precisely understanding what it is you want 
to do is often 90% of doing it.

> I am fine with this except finding all the matches. Could anyone 
> explain how to do this with index?

To do that you'd need to slurp the whole file into a string (see FAQ) 
but this is far form a natural approach.

my $pos=0;
while ( ( $pos = index( $file_content, $target, $pos )) > -1 ) {
   # Do stuff with $file_content and $pos
}

> Or is there some other way (please 
> try to keep it simple if you can :)

Yes there are much simpler ways.  But first you need to step back and 
consider what you really want to do.

 > I want to locate & save to an array all lines begging with "*".

Hmmm... ok now we are perhaps getting closer.

my @lines_starting_with_asterisk;
local *_;
while(<FILE>) {
   push @lines_starting_with_asterisk => $_ if /^\*/;
}

 > I
 > presume I will then be able to use split to get the raw prices out of
 > the array (in between the "<").

But why do you think you need an array?  Can you not simply process the 
stuff as you read it from the file?

The split() function is good if you have a delimited list of arbitrary 
length but the usual way to structured text in Perl is just the simple 
pattern match.  Simply write a pattern that matches the lines you are 
interested in and captures the interesting parts of the line.

local *_;
while(<FILE>) {
   next unless my ($item, $price)=/^\*(.*?)<(.*?)</;
   # Do stuff with $item and $price.
}



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

Date: Fri, 25 Mar 2005 13:20:37 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie help - finding all substrings with index?
Message-Id: <d212s7$l34$2@sun3.bham.ac.uk>



Brian McCauley wrote:

> Anyhow I think you are expressing what you want carefully.

Opps, should have said "... _not_ expressing...".

Gee, that's kinda embarrasing. :-)



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

Date: 23 Mar 2005 11:09:20 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: newbie question
Message-Id: <yzdvf7ir7vz.fsf@invalid.net>


Tad McClellan <tadmc@augustmail.com> writes:
> usr <usr@nomail.mail> wrote:
> 
> > I'm using linux and this is my code
> > /usr/bin/perl
> > print "Hello, World!\n";
> 
> 
>    #!/usr/bin/perl
>    print "Hello, World!\n";

Just adding some information: what happened when the #! sequence
wasn't present was that the program /usr/bin/perl was called in the
ordinary way from the script. And when called without any arguments,
it just sits and waits for input (on standard input, not from the
script being executed) to treat as Perl code and execute.


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

Date: 25 Mar 2005 21:33:07 -0800
From: JanVdVogel@hotmail.com (JanVDV)
Subject: newbie question: display xmlfile
Message-Id: <5e3d1dc7.0503252133.64159f42@posting.google.com>

Hello,

I'm pretty new with perl.
I want to display an xml file in a browser, but I don't know how.
My xml file is coppled to an xsl stylesheet, so I don't think I can
do something with XML::Parser.
(so, to be clear; if I type somescript.cgi in my browser, I want to have
the information of the xml file, transformed with xslt).
Can you people help me out? I think it is quite simple, but I can't find
the answer anywhere.

thankx
JanVDV


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

Date: Sat, 26 Mar 2005 09:19:03 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie question: display xmlfile
Message-Id: <d2393b$mor$1@sun3.bham.ac.uk>



JanVDV wrote:

> I'm pretty new with perl.

Your question has nothing to do with Perl - but this is not obvious so 
you are forgiven.

> I want to display an xml file in a browser, but I don't know how.
> My xml file is coppled to an xsl stylesheet, so I don't think I can
> do something with XML::Parser.
> (so, to be clear; if I type somescript.cgi in my browser, I want to have
> the information of the xml file, transformed with xslt).
> Can you people help me out? I think it is quite simple, but I can't find
> the answer anywhere.

Please see recent thread "cant display generated html in browser (perl 
script)" in this newsgroup where I explained this to someone else.




> thankx
> JanVDV



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

Date: Sat, 26 Mar 2005 19:45:30 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: newbie question: display xmlfile
Message-Id: <uZi1e.113406$H05.48603@twister.nyroc.rr.com>

JanVDV wrote:

 ...

> I want to display an xml file in a browser, but I don't know how.

Did you try something like:

     file:///d:/junk/junk78.xml

in your brower's URL box?  That displays an XML file on my 
browser (Mozilla 1.7.3).

And, BTW, that has nothing to do with Perl, and so is off-topic 
in this newsgroup.

 ...

> JanVDV

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 26 Mar 2005 13:21:45 -0800
From: "robic0@yahoo.com" <robic0@yahoo.com>
Subject: Re: newbie question: display xmlfile
Message-Id: <1111872105.191257.88140@o13g2000cwo.googlegroups.com>

90% of the topics in this group theorehtically "have nothing to do with
Perl".
Perl without application is useless. Seems your group charter is just
Perl, without
examples. Textbooks have examples. If you don't want usages' why does
your
newsgroup exist? Theres no such thing as theorehtical programing
languages'.
You had better parse your words better to not weigh the outcome in your
favor
or better define what is/isn't on/off topic.
I suggest that if you act like this is your personal board that you
dynamically
interpret rules, not alot of interested parties will come to your
"lang" board.

-my $.02



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

Date: Sat, 26 Mar 2005 16:47:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: newbie question: display xmlfile
Message-Id: <slrnd4bpjs.1l9.tadmc@magna.augustmail.com>

robic0@yahoo.com <robic0@yahoo.com> wrote:

> not alot of interested parties will come to your
> "lang" board.


Bummer, since we get paid by the volume of traffic.


(and this is not a "board", it is a "newsgroup". The dynamics
 are quite different between the 2 environments.
)

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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 7915
***************************************


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