[17901] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 61 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 15 03:05:51 2001

Date: Mon, 15 Jan 2001 00:05:11 -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: <979545910-v10-i61@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 15 Jan 2001     Volume: 10 Number: 61

Today's topics:
        Call C function in XS from C function in the same XS fi <john@imining.com.tw>
        file handle pointer bolero92@my-deja.com
    Re: file handle pointer <tony_curtis32@yahoo.com>
    Re: file handle pointer <jbuff1856@my-deja.com>
    Re: Help me append (David H. Adler)
    Re: how to test if $a is part of $b?? (Colin Watson)
        LWP::UserAgent request failing. debug trace <robert@chalmers.com.au>
        LWP::UserAgent with HTTP::Cookies not keeping cookies ? snakedjip@yahoo.com
        moving files from directories <bac2@duke.edu>
    Re: moving files from directories (Bernard El-Hagin)
    Re: Need Help - Cookies vs. Browser (browser leads 2-1) (Abigail)
        Need some  expert guidance with HTTP::Request (LWP, lib <robert@chalmers.com.au>
        only writing partail data to file <rhillatmay@my-deja.com>
    Re: overload not autogenerating as expected <rick.delaney@home.com>
        Problem with escaping + $ , djin1@hotmail.com
    Re: Problem with escaping + $ , <Peter.Dintelmann@dresdner-bank.com>
    Re: Regular Expression Question (Tad McClellan)
    Re: Regular Expression... can I use a $var to represent <zarathustra@enviroweb.org>
    Re: Regular Expression... can I use a $var to represent <zarathustra@enviroweb.org>
    Re: Shall use a reference instead? <michael-a-mayo@worldnet.att.net>
        Split problem <whataman@home.com>
    Re: Split problem (Tad McClellan)
    Re: Split problem <jhelman@wsb.com>
    Re: Split problem <jhelman@wsb.com>
    Re: Split problem <whataman@home.com>
    Re: Split problem <whataman@home.com>
    Re: Split problem <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 15 Jan 2001 10:50:47 +0800
From: "John" <john@imining.com.tw>
Subject: Call C function in XS from C function in the same XS file
Message-Id: <93tos9$ium@netnews.hinet.net>

Hi:

I have a function ShowCounter() in WebGet.xs
When I call ShowCounter() from another function in WebGet.xs, I get the
following error.

perl: error in loading shared libraries: blib/arch/auto/WebGet/WebGet.so:
undefined symbol: ShowCounter

But I can call ShowCounter() from my perl program that use module WebGet.
I really have to call ShowCounter() in other C functions in WebGet.xs.
How should I do?

Thanks in advance.

John Hsieh
john@imining.com.tw




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

Date: Mon, 15 Jan 2001 03:29:57 GMT
From: bolero92@my-deja.com
Subject: file handle pointer
Message-Id: <93tqrh$gv3$1@nnrp1.deja.com>

seek() is a function to set the position of current file handle.
what is the reverse of it?

in another words,
which function can I use to store the location of current file handle
position?


Sent via Deja.com
http://www.deja.com/


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

Date: 14 Jan 2001 21:48:37 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: file handle pointer
Message-Id: <87bst9pjai.fsf@limey.hpcc.uh.edu>

>> On Mon, 15 Jan 2001 03:29:57 GMT,
>> bolero92@my-deja.com said:

> seek() is a function to set the position of current file
> handle.  what is the reverse of it?

> in another words, which function can I use to store the
> location of current file handle position?

I think you want "tell" but I don't think "reverse of
[seek]" is a good description of what tell is.

    perldoc -f tell

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Mon, 15 Jan 2001 03:48:57 GMT
From: jbuff <jbuff1856@my-deja.com>
Subject: Re: file handle pointer
Message-Id: <93trv8$hs6$1@nnrp1.deja.com>

In article <93tqrh$gv3$1@nnrp1.deja.com>,
  bolero92@my-deja.com wrote:
> seek() is a function to set the position of current file handle.
> what is the reverse of it?
>
> in another words,
> which function can I use to store the location of current file handle
> position?
>
>

perldoc -f tell

-- jbuff



Sent via Deja.com
http://www.deja.com/


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

Date: 15 Jan 2001 04:23:42 GMT
From: dha@panix6.panix.com (David H. Adler)
Subject: Re: Help me append
Message-Id: <slrn964uqe.3d7.dha@panix6.panix.com>

On 13 Jan 2001 23:28:43 GMT, Colin Watson <cjw44@flatline.org.uk> wrote:
>
> Brian Foy

That's 'brian d foy'.  See <http://www.panix.com/~comdog/style.html>
for details.

Thanks, though.  It makes a change from chastising people for job
posts. :-)

dha, Sgt at arms

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"It's all in the mind." - Madness


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

Date: 15 Jan 2001 01:12:40 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: how to test if $a is part of $b??
Message-Id: <93tiq8$dl3$1@riva.ucam.org>

Michael Cook <mikecook@cigarpool.com> wrote:
>"Me" <ja@nee.snee> wrote in message
>news:tEY8Y#hfAHA.254@asd24-aux-005.raketnet.nl...
>> If $a="this is a test"
>> and $b=" is a"
>>
>> how would one test if $b is a part of $a ????
>
>See if this works for you:
>~~~~~
>#!/bin/perl

#!/bin/perl -w
use strict;

>$a="this is a test";
>$b=" is a";

Under 'use strict', 'my $a' and 'my $b'. Oh, of course, you ought to
call lexicals (and variables in general) something other than $a and $b;
see 'perldoc -f sort'.

>if ( $a =~ $b )

'$a =~ /\Q$b/' would be a much better condition, as regex metacharacters
in $b won't then be interpreted as special in the regular expression,
but instead as ordinary characters.

Or, of course, you could use index() instead, as somebody else
mentioned.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"I believe in toasters / They can make my toast
 Chrome and black and powerful / Are the ones I like the most"
 - The Toaster Song, various perpetrators


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

Date: Mon, 15 Jan 2001 16:11:19 +1000
From: "Merlin" <robert@chalmers.com.au>
Subject: LWP::UserAgent request failing. debug trace
Message-Id: <sCw86.69$CM6.17560@nsw.nnrp.telstra.net>

This is the trace in its entirety from the perl script unsuccessfully called
via the cgi program.

LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: POST
https://sec.aba.net.au/cgi-bin/service/authorise/test
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
Can't call method "request" on an undefined value at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/UserAgent.pm line 227.

===============================

This is the top part of the successful run from just the perl program.
(command line)
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: POST
https://sec.aba.net.au/cgi-bin/service/authorise/test
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: POST /cgi-bin/service/authorise/test
HTTP/1.0^M
Host: sec.aba.net.au^M
User-Agent: AgentName/0.1 libwww-perl/5.50^M
=============================

Both bits of code are exactly the same. The one in the cgi as a subroutine
fails, the commandline script works.

Can anyone shed some light on this at all - you'll have a friend for life
:-)

thanks
Robert



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

Date: Mon, 15 Jan 2001 04:06:04 GMT
From: snakedjip@yahoo.com
Subject: LWP::UserAgent with HTTP::Cookies not keeping cookies ???
Message-Id: <93tsv9$igh$1@nnrp1.deja.com>

Hello,

Straight to the point, here's my code :

use LWP::UserAgent;
use LWP::Debug qw(+conns +trace +debug);
use HTTP::Cookies;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request 'GET','http://<MyIp>:8081/default.asp';
my $res = $ua->request($req);
my $cookie_jar = new HTTP::Cookies;
$cookie_jar->extract_cookies($res);
print "\n\nCookies: " . $cookie_jar->as_string . "\n\n";

print header;
if ($res->is_success) {
    my $req = new HTTP::Request 'GET'
=> 'http://<MyIp>:8081/default.asp';
    $cookie_jar->add_cookie_header($req);
    $res = $ua->request($req);
    if ($res->is_success){
	$response = $res->as_string;
	print $response;
    }
} else {
    print $res->status_line;
}



THE PROBLEM :
-------------

When I access this default page with a browser for the first time,
since this is a Microsoft ASP page, a cookie is sent to my browser to
identify the session id.  If I "reload" the page in the browser, that
cookie is sent to the server upon its request for it...  I verified in
the server's log, and the cookie appears in it (with the W3C extended
logging enabled in IIS, this is possible...)

So far so good.

Now, I want to reproduce this behaviour with LWP::UserAgent and
HTTP::Cookies.

So (commenting my code here...), I "GET" the url a first time, I create
the HTTP::Cookies object to store the received session id, and when I
try to re-GET the page, for some reason, $cookie_jar->add_cookie_header
($req) doesn't do the job.  The cookie is never sent to the server.  In
fact, the $cookie_jar->as_string method returns NOTHING !


WHY ?

I tried the same code on another site and it works just fine...

Is it because my URL is constructed with a numeric IP instead of a
domain name ?

Is it because my server is on port 8081 ?


Any help would be greatly appreciated.  Thank you for your time.




Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 15 Jan 2001 01:56:27 -0500
From: Blossom Coryat <bac2@duke.edu>
Subject: moving files from directories
Message-Id: <Pine.SOL.3.91.1010115014546.4036A-100000@godzilla1.acpub.duke.edu>



hi everyone, another newbie here.
How would i move files that are 2weeks old in a directory into a 
sub-directory within that same directory according to the first letter 
of the file name?

thanks, 
Blossom
bac2@duke.edu



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

Date: Mon, 15 Jan 2001 07:27:29 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: moving files from directories
Message-Id: <slrn9659j0.2q0.bernard.el-hagin@gdndev25.lido-tech>

On Mon, 15 Jan 2001 01:56:27 -0500, Blossom Coryat <bac2@duke.edu>
wrote:
>
>
>hi everyone, another newbie here.
>How would i move files that are 2weeks old in a directory into a 
>sub-directory within that same directory according to the first letter 
>of the file name?

These documents should help. After you've read them and came up with
something and it doesn't work the way you want it to, post it and
someone will help you.

perldoc -f stat (for the age of the file)
perldoc -f rename (for moving files)
perldoc -f substr (for getting the first letter of the filename)
perldoc -f lc or perldoc -f uc (for dealing with lower- or uppercase
                                first letters in the filenames)
perldoc -f mkdir (for creating the directory. i'm not sure if the
		          subdirs exist or not)

Cheers,
Bernard
--
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


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

Date: 15 Jan 2001 01:13:33 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Need Help - Cookies vs. Browser (browser leads 2-1)
Message-Id: <slrn964jlt.ord.abigail@tsathoggua.rlyeh.net>

Mike (mike@customautotrim.com) wrote on MMDCXCIII September MCMXCIII in
<URL:news:3A61FE2D.3907B1EB@customautotrim.com>:
-- We are going to be using cookies that we will be setting via Perl
-- cgi-scripts. We have 3 problems though:
-- 1. Netscape doesn't seem to recognize our cookies when we set the
-- domain= to our domain which is customautotrim.com.

That's not a Perl issue, it's a browser issue.

-- 2. we use multiple domains for our web site i.e. customautotrim.com,
-- factorywooddash.com, etc., how do we keep each domain from leaving a
-- different cookie

That's not a Perl issue, it's a server config issue.

-- 3. if the person surfing our web site doesn't have cookies on in their
-- browser, how do we determine that?

That's not a Perl issue, it's an HTTP issue. (If the browser ignores
cookies, you won't get any back - amazingly, isn't it?)



Abigail
-- 
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail


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

Date: Mon, 15 Jan 2001 09:40:43 +1000
From: "Merlin" <robert@chalmers.com.au>
Subject: Need some  expert guidance with HTTP::Request (LWP, libwww) and returned error. Short test code included
Message-Id: <kUq86.25$CM6.7001@nsw.nnrp.telstra.net>


This is a little strange. I'm sure I'm missing something simple here.

If I put this little bit of code into a script of it's own. test.pl say,
with #!/usr/local/bin/perl at the start etc. remove the 'sub esecpay {' and
closing '}', and run it, it works - returning the appropriate response. In
other words, it appears to work fine, and do what it's suposed to do.
however, .... when I call it as  subroutine it comes up with the error shown
just below the code..

=================================
sub esecpay {

use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
#create request
my $req = new HTTP::Request POST =>
'https://sec.aba.net.au/cgi-bin/service/authorise/test';
$req->content_type('application/x-www-form-urlencoded');
$req->content('&secParams=https://sec.aba.net.au/merchant/test/testpayment.p
rops &referenceID=xxx &cardType="ABA Test" &cardNumber=abasuccess
&nameOnCard=Robert &
expiryMonth=3 &expiryYear=2002 &amount=45.00
&resultURL=http://www.chalmers.com.au/~robert/allvars.php3');
#Pass request and get response
my $res = $ua->request($req);
#Check response
if ($res->is_success) {
   print $res->content;
} else {
   print $res->status_line;
}

}
======================

If I call the bit of code as a subroutine, it returns this .....
------------------------------------
Can't call method "request" on an undefined value at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/UserAgent.pm line 227.
---------------------------------------

It appers to be not getting the request passed to it? but I can't figure out
why? if it works as a standalone, why not as a subroutine?

Thanks for any help, I'm really stuck on this.
Robert



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

Date: Mon, 15 Jan 2001 05:40:02 GMT
From: r hill <rhillatmay@my-deja.com>
To: roger_hill@may-co.com
Subject: only writing partail data to file
Message-Id: <93u2fi$moi$1@nnrp1.deja.com>

Calling all Perl Experts!!!

I have a Form with a TextArea that I'm
parsing out and then writing the data into
a file. There is a large amount of data in the
TEXTAREA, (100+ lines) what I end up getting is
about 1/3 of the data from the textarea into the
actual file. It seems like the buffer is not big
enough to handle all of the lines of text in the
TEXTAREA. I'm using the POST method, when trying
calling the script to do the write.

My script actually works for smaller chunks of data,
but not large ones(like I'm trying to send) I will
post some of my code tommorrow.

Roger Hill
Programmer Analyst


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 15 Jan 2001 04:47:32 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: overload not autogenerating as expected
Message-Id: <3A6284C2.96E80B87@home.com>


mintcake@my-deja.com wrote:
> 
> Operation `eq': no method found,
>         left argument in overloaded package Foo,
>         right argument has no overloaded magic at foo.pl line 10.
> 
> #!/usr/bin/perl -w
> 
> package Foo;
> use overload qw("") => sub { '*' . $_[0]->{key} . '*' };

You'll want to use the fallback key here:

    use overload 
        q("")    => sub { '*' . $_[0]->{key} . '*' },
        fallback => 1;

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Mon, 15 Jan 2001 06:13:41 GMT
From: djin1@hotmail.com
Subject: Problem with escaping + $ ,
Message-Id: <93u4ei$o0n$1@nnrp1.deja.com>

I am using URI::Escape to escape charaters. However, "+", "$" and ","
can't seem to be escaped to their respective escaped characters. It
just shows up as unescaped. I am using perl 5.005_03. The module that I
installed is the latest which is URI-1.10. Any ideas?

Gene


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 15 Jan 2001 08:44:03 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: Problem with escaping + $ ,
Message-Id: <93u9p7$rbv1@intranews.bank.dresdner.net>

    Hi Gene,

<djin1@hotmail.com> wrote in message news:93u4ei$o0n$1@nnrp1.deja.com...
> I am using URI::Escape to escape charaters. However, "+", "$" and ","
> can't seem to be escaped to their respective escaped characters.

    '+', ',' and '$' are not escaped by default (see the
    URI::Escape manpage).

    The URI::Escape manapage suggets to use

        use URI::Escape;
        $verysafe = uri_escape("foo", "\0-\377");

    Regards,

        Peter Dintelmann





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

Date: Sun, 14 Jan 2001 14:39:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expression Question
Message-Id: <slrn96403g.acl.tadmc@tadmc26.august.net>

Bob Simon <bob_simon@my-deja.com> wrote:

>b) [A-Za-z]* means zero or more occurrences of any capital
>or small letter and appears to match the null string.
>
>For consistency, it seems like [A-Za-z]* should match the
>first n letters in a line, up to the first space, or
>non-alphabetic char.  Where is the error in this logic?


It matches at the first opportunity.

If matching against  '123abc', the first opportunity is the
empty string before the '1' character, so that is what it
matches.

Don't allow it to match the empty string if you don't want
it to match the empty string:

   [A-Za-z]+


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


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

Date: Sun, 14 Jan 2001 23:06:13 GMT
From: "Vogelfrei" <zarathustra@enviroweb.org>
Subject: Re: Regular Expression... can I use a $var to represent it?
Message-Id: <Fhq86.17167$ag.495267@newsread2.prod.itd.earthlink.net>


"Dr Joolz" <julius_mong@hotmail.com> wrote in message
news:L6n86.1682$ye3.49450@news2-win.server.ntlworld.com...
> my $reg =
>
"[+-]?[0-9]+(\.[0-9]+)?(\s*,\s*|\s+,?\s*|\s*,?\s+)[+-]?[0-9]+(\.[0-9]+)?(\s*
>
,\s*|\s+,?\s*|\s*,?\s+)[+-]?[0-9]+(\.[0-9]+)?(\s*,\s*|\s+,?\s*|\s*,?\s+)[+-]
> ?[0-9]+(\.[0-9]+)?";
>
> if ($regexp =~ /^$reg$/) {
>  print "\nMatched";
> } else {
>  print "\nUnmatched";
> }


my $reg =
qr/[+-]?[0-9]+(\.[0-9]+)?(\s*,\s*|\s+,?\s*|\s*,?\s+)[+-]?[0-9]+(\.[0-9]+)?(\
s*
,\s*|\s+,?\s*|\s*,?\s+)[+-]?[0-9]+(\.[0-9]+)?(\s*,\s*|\s+,?\s*|\s*,?\s+)[+-]
?[0-9]+(\.[0-9]+)?/;

print "\n", $regexp =~ /^$reg$/ ? 'Matched' : 'Unmatched';
print "\n", join(' ', $1..$7), "\n"




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

Date: Sun, 14 Jan 2001 23:12:59 GMT
From: "Vogelfrei" <zarathustra@enviroweb.org>
Subject: Re: Regular Expression... can I use a $var to represent it?
Message-Id: <%nq86.17196$ag.496346@newsread2.prod.itd.earthlink.net>


"Vogelfrei" <zarathustra@enviroweb.org> wrote in message
news:Fhq86.17167$ag.495267@newsread2.prod.itd.earthlink.net...
>


> print "\n", join(' ', $1..$7), "\n"

Sorry please ignore this last line. Thought I was in the editor; only
playing around.




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

Date: Mon, 15 Jan 2001 06:16:44 GMT
From: "Michael Mayo" <michael-a-mayo@worldnet.att.net>
Subject: Re: Shall use a reference instead?
Message-Id: <gBw86.1924$4y6.144227@bgtnsc07-news.ops.worldnet.att.net>

"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote
> It may seem like pure semantics, but conceptually distinguishing
> referent (_the_ object) from reference (_a_ scalar) is IMHO the
> correct view. When you "bless a reference", you really "bless the
> reference's value" (the thingy)

OK, I'm convinced.  My original statement was wrong; the blessed thingie is the
object.

        -Mike




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

Date: Mon, 15 Jan 2001 02:17:33 GMT
From: "What A Man !" <whataman@home.com>
Subject: Split problem
Message-Id: <3A625E24.A3B1104C@home.com>

I have   0 03-21-00 15:53 MyFile/   in $list[3] but just
want to pull out MyFile/ and put it into another scalar.
How do I do this?

I've tried this and it doesn't work.
$lis = $list[3];
@lis = split(/ /);
print $lis[3];

I've studied perlfunc split for hours and just can't get
it.

Thanks,
Dennis


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

Date: Sun, 14 Jan 2001 19:51:44 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Split problem
Message-Id: <slrn964id0.bg2.tadmc@tadmc26.august.net>

What A Man ! <whataman@home.com> wrote:
>I have   0 03-21-00 15:53 MyFile/   in $list[3] but just


We speak Perl here. Perl is unambiguous (compared to natural
language). In Perl we say the above this way:

   $list[3] = '0 03-21-00 15:53 MyFile/';

Speaking Perl is better than English when discussing code.


>want to pull out MyFile/ and put it into another scalar.
>How do I do this?


   $_ = '0 03-21-00 15:53 MyFile/';
   my @lis = split(/ /);
   print $lis[3];

or, probably better:

   my $path = (split / / )[3];
   print $path;


>I've tried this and it doesn't work.
>$lis = $list[3];
>@lis = split(/ /);

>I've studied perlfunc split for hours and just can't get
>it.


Have you really?

What does split() use for a string to split when you do not
provide one as an argument?

Have you put anything into $_?

Do you have warnings enabled?

Do you have

   use strict;

in your program?



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


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

Date: Mon, 15 Jan 2001 03:18:34 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Split problem
Message-Id: <3jq46tk4s23992c6btolnjq90el7l7n3td@4ax.com>

On Mon, 15 Jan 2001 02:17:33 GMT, "What A Man !" <whataman@home.com>
wrote:

>I have   0 03-21-00 15:53 MyFile/   in $list[3] but just
>want to pull out MyFile/ and put it into another scalar.
>How do I do this?
>
>I've tried this and it doesn't work.
>$lis = $list[3];
>@lis = split(/ /);
>print $lis[3];

Okay, assuming there are no leading spaces before the 0 in your file
and your variable is in $list[3]:

my @lis = split(/ /, $list[3]);
print "$lis[3]";

should print your desired result.  Note that in the documentation for
split, it reads, in part:

split /PATTERN/

{SNIP}

If EXPR is omitted, splits the $_ string.

Thus, to use split without specifying the variable you are splitting,
you need to explicitly set $_ to your variable.  This could be
accomplished with the following code, but the above code is more
efficient and easier to read.

$_ = list[3];
@lis = split(/ /);
print "$lis[3]";

'Course, this also only works if there aren't any leading spaces in
your line.  If there are, and if you decide you want to get rid of
them, just put the following line before your split() call:

$list[3] =~ s/^\s+//;

Hope this helps,
JH


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

Date: Mon, 15 Jan 2001 03:24:54 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Split problem
Message-Id: <vbr46tk92gu134mcn844m152aqda67kdmo@4ax.com>

On Mon, 15 Jan 2001 03:18:34 GMT, Jeff Helman <jhelman@wsb.com> wrote:

>$_ = list[3];

Whoops. Make that:

$_ = $list[3];

JH


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

Date: Mon, 15 Jan 2001 05:14:23 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Split problem
Message-Id: <3A628796.A9F5EEE1@home.com>

Thanks Jeff, but neither of those examples worked. $lis[3]
is giving me "15:53" ...and when I try $lis[4], the output
is either 0 or nothing. I just can't get that last piece
of the string. Got any ideas why?


Jeff Helman wrote:
> 
> On Mon, 15 Jan 2001 02:17:33 GMT, "What A Man !" <whataman@home.com>
> wrote:
> 
> >I have   0 03-21-00 15:53 MyFile/   in $list[3] but just
> >want to pull out MyFile/ and put it into another scalar.
> >How do I do this?
> >
> >I've tried this and it doesn't work.
> >$lis = $list[3];
> >@lis = split(/ /);
> >print $lis[3];
> 
> Okay, assuming there are no leading spaces before the 0 in your file
> and your variable is in $list[3]:
> 
> my @lis = split(/ /, $list[3]);
> print "$lis[3]";

{SNIP}
> $_ = $list[3[;
> @lis = split (/ /);
> print "$lis[3]";


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

Date: Mon, 15 Jan 2001 05:24:58 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Split problem
Message-Id: <3A628A12.7F23FF34@home.com>

Tad McClellan wrote:
> 
> What A Man ! <whataman@home.com> wrote:
> >I have   0 03-21-00 15:53 MyFile/   in $list[3] but just
> 
> We speak Perl here. Perl is unambiguous (compared to natural
> language). In Perl we say the above this way:
> 
>    $list[3] = '0 03-21-00 15:53 MyFile/';
> 
> Speaking Perl is better than English when discussing code.
> 
Makes sense. I see what you mean. I hadn't thought of it
like that. I'll try to speak in Perl next time.

> >want to pull out MyFile/ and put it into another scalar.
> >How do I do this?
> 
>    $_ = '0 03-21-00 15:53 MyFile/';
>    my @lis = split(/ /);
>    print $lis[3];
> 
> or, probably better:
> 
>    my $path = (split / / )[3];
>    print $path;
> 
> >I've tried this and it doesn't work.
> >$lis = $list[3];
> >@lis = split(/ /);
I don't know the value of $lis[3] ahead of time.
> 
> >I've studied perlfunc split for hours and just can't get
> >it.
> 
> Have you really?
> 
Yes.

> What does split() use for a string to split when you do not
> provide one as an argument?
Point taken.
> 
> Have you put anything into $_?
No.
> 
> Do you have warnings enabled?
Yes.
> 
> Do you have
> 
>    use strict;
> 
> in your program?
No, but I did use -d... does that count?


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

Date: Sun, 14 Jan 2001 22:21:57 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Split problem
Message-Id: <3A629705.66DC930C@stomp.stomp.tokyo>

"What A Man !" wrote:
 
> I have   0 03-21-00 15:53 MyFile/   in $list[3] but just
> want to pull out MyFile/ and put it into another scalar.
> How do I do this?


(snip) 


TEST SCRIPT:
____________


#!/usr/local/bin/perl

print "Content-type: text/plain\n\n";


$input = "0 03-21-00 15:53 MyFile/";

$start = rindex ($input, " ");

$output = substr ($input, $start, length ($input) - $start);

print $output;


exit;



PRINTED RESULTS:
________________

MyFile/




Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

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 V10 Issue 61
*************************************


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