[22799] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5020 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 14:05:44 2003

Date: Wed, 21 May 2003 11:05:13 -0700 (PDT)
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, 21 May 2003     Volume: 10 Number: 5020

Today's topics:
    Re: calling an exe file <ThomasKratz@REMOVEwebCAPS.de>
        Can I save my sourcecode from the Perl debugger? (Sara)
        Code to check which button press <ddl76@singnet.com.sg>
        Collecting Stats (split/DBI:mysql) <andrew.rich@bigpond.com>
    Re: finding "mailto:" strings in html files (Netware60)
    Re: finding "mailto:" strings in html files <no@spam.for.me.invalid>
        FORM/CGI: submit a file <Mael.Guillemot@idiap.ch>
    Re: FORM/CGI: submit a file <Mael.Guillemot@idiap.ch>
    Re: Install/setup Net::SSH::PERL (Randy Kobes)
        NET:SNPP help <roach@kronic.net>
    Re: o conf urllist <palladium@spinn.net>
        Recursion and Filehandles <thens@nospam.com>
    Re: Recursion and Filehandles (Veky)
    Re: Recursion and Filehandles <nobull@mail.com>
    Re: Recursion and Filehandles <ThomasKratz@REMOVEwebCAPS.de>
        Shutting Down Windoze <andrew.rich@bigpond.com>
    Re: Shutting Down Windoze (Veky)
    Re: Shutting Down Windoze <nobull@mail.com>
    Re: Shutting Down Windoze <usenet@dwall.fastmail.fm>
    Re: The n'th character of a string <andrew.rich@bigpond.com>
    Re: The n'th character of a string <wksmith@optonline.net>
    Re: The n'th character of a string (Veky)
        What does this mean ? <andrew.rich@bigpond.com>
    Re: What does this mean ? (Veky)
    Re: What does this mean ? <john.thetenant-s@moving-picture.com>
    Re: What does this mean ? <andrew.rich@bigpond.com>
    Re: What does this mean ? <nobull@mail.com>
        worth a look <johndwyer@primemail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 21 May 2003 19:43:02 +0200
From: "Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: calling an exe file
Message-Id: <3ecbc2ab.0@juno.wiesbaden.netsurf.de>

DQoiQWxsYW5vbiIgPGFsbGFub25AaG90bWFpbC5jb20+IHdyb3RlLi4uDQo+ICJJc2xhdyIgPGlz
bGF3QGFkZXhlYy5jb20+IHdyb3RlIGluIG1lc3NhZ2UNCj4gbmV3czpiaEZ5YS40NjYzJFlTNC4z
MzkxQG5ld3NzdnIxNy5uZXdzLnByb2RpZ3kuY29tLi4uDQo+IFsuLl0NCj4gPiBPciBpZiB0aGUg
b3V0cHV0IGlzIG5lZWRlZCB0byBiZSBjYXB0dXJlZDoNCj4gPg0KPiA+IG15ICRvdXQgPSBgYzov
dGVzdC90ZXh0LmV4ZSAyPiYxYA0KPiANCj4gVGhhdCdzIHVzZWZ1bCB0byBrbm93IDopDQo+IA0K
PiBDYW4geW91IGV4cGxhaW4gd2hhdCB0aGUgIjI+JjEiIGJpdCBhY3R1YWxseSBtZWFucy9kb2Vz
IGNoYXItYnktY2hhci4NCg0KVW5peCBzaGVsbHMgKCphbmQqIHRoZSBjbWQgc2hlbGwgdW5kZXIg
d2luMzIpIHRyZWF0IG51bWJlcnMgaW4gY29ubmVjdGlvbiB3aXRoIHBpcGluZyBvciByZWRpcmVj
dGlvbiBzeW1ib2xzIGFzIGRlc2NyaXB0b3JzIGZvciBzdGRpbigwKSwgc3Rkb3V0KDEpIGFuZCBz
dGRlcnIoMikuDQoNClRoZSBhYm92ZSBtZWFucyAicmVkaXJlY3Qgd2hhdCdzIHNlbnQgdG8gc3Rk
ZXJyIHRvIHRoZSBzYW1lIHBsYWNlIHdoZXJlIHN0ZG91dCBpcyBzZW50Ii4gQW5kIGJ5IGNhcHR1
cmluZyB0aGUgb3V0cHV0IHdpdGggYmFja3RpY2tzIHlvdSB3aWxsIGdldCBib3RoIHN0ZG91dCBh
bmQgc3RkZXJyIGZyb20gcnVubmluZyB0ZXN0LmV4ZS4NCg0KVGhvbWFzDQo=



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

Date: 21 May 2003 10:44:16 -0700
From: genericax@hotmail.com (Sara)
Subject: Can I save my sourcecode from the Perl debugger?
Message-Id: <776e0325.0305210944.24c8ce28@posting.google.com>

Ack- I have a debug session open with my current sources loaded, but
in the meantime a sysadmin clobbered all of my sourcecode. Is there
any way to save the sources from the debugger? I looked at debug help
and searched this group I don't see it.

I know I could list the whole script and save it but is there a way to
export it to a file?

Thanks,
Gx


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

Date: Wed, 21 May 2003 23:17:30 +0800
From: "ldd" <ddl76@singnet.com.sg>
Subject: Code to check which button press
Message-Id: <bag4mg$8tg$1@mawar.singnet.com.sg>

Hi all,

I have a HTML form with few buttons. I need to check which button is pressed
in my .pl script and then call the respective sub to process the data.
Anyone any idea?

Thanks
ldd




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

Date: Thu, 22 May 2003 01:50:07 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Collecting Stats (split/DBI:mysql)
Message-Id: <pan.2003.05.21.15.50.07.138495@bigpond.com>

Wonder what would be the best way to do this ?
I want to split up readings for 24 hours and insert them into a database.
eg

data,2,3,2,2,3,4,23,2,34,3,2,2,3,4,4,3,2,2,33,55,22,334,332,22

Would I best use split ? 

I know the database bit off by heart. 

#!/usr/bin/perl
use DBI;

<open file code would go here>

<split code would go here>

my $database_handler = DBI->connect("DBI:mysql:stats:host=host","root","");
$sql ="insert into data values ( <data will go here> )";
$statement_handler=$database_handler->prepare ($sql);
$statement_handler->execute;
$statement_handler->finish;
$database_handler->disconnect;
exit;







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

Date: 21 May 2003 09:37:24 -0700
From: clos@trentu.ca (Netware60)
Subject: Re: finding "mailto:" strings in html files
Message-Id: <55964b31.0305210837.558ead92@posting.google.com>

"Nils Petter Vaskinn" <no@spam.for.me.invalid> wrote in message news:<pan.2003.05.21.11.24.15.112532@spam.for.me.invalid>...
> On Wed, 21 May 2003 03:50:56 -0700, Netware60 wrote:
> 
> > I need to search thru a list of html text files and find and extract
>  [snip extract mailto from html]
> > TIA
> 
> I think you'll have to tell why you want to do this or a lot of people
> will assume you are harvesting email addresses for spam, and choose not to
> help you.
> 
> NPV

We just want to find out how many of our web publishers are putting
"mailto:"s in their pages.  I am *not* doing address harvesting, we
are trying to take harvest counter measures by reducing the incidence
of mailto use at our site. So we're just trying to find out whose
using it at our site. Thats all.


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

Date: Wed, 21 May 2003 16:39:59 GMT
From: "Nils Petter Vaskinn" <no@spam.for.me.invalid>
Subject: Re: finding "mailto:" strings in html files
Message-Id: <pan.2003.05.21.16.40.01.156851@spam.for.me.invalid>

On Wed, 21 May 2003 09:37:24 -0700, Netware60 wrote:

> We just want to find out how many of our web publishers are putting
> "mailto:"s in their pages.  I am *not* doing address harvesting, we
> are trying to take harvest counter measures by reducing the incidence
> of mailto use at our site. So we're just trying to find out whose
> using it at our site. Thats all.

Basically using the spammers tool against them to ensure that the spammers
won't catch anything :)

I believe you got a suitable regexp in another post.


NPV


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

Date: Wed, 21 May 2003 17:26:47 +0200
From: Mael Guillemot <Mael.Guillemot@idiap.ch>
Subject: FORM/CGI: submit a file
Message-Id: <3ECB9AB6.99480C8C@idiap.ch>

Hi everybody!

I am trying to do a dialog box button for directory browsing on local
disk using POST method from the HTML FORM element. I want the user to
submit a file. Does anybody knows how to make it?

Do I need a library such that libwww-perl to do that?

thanks,

Maël





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

Date: Wed, 21 May 2003 18:12:56 +0200
From: Mael Guillemot <Mael.Guillemot@idiap.ch>
Subject: Re: FORM/CGI: submit a file
Message-Id: <3ECBA588.8BA15C94@idiap.ch>

Uploading Files Using CGI and Perl


http://www.sitepoint.com/article/474/2



Mael Guillemot wrote:

> Hi everybody!
>
> I am trying to do a dialog box button for directory browsing on local
> disk using POST method from the HTML FORM element. I want the user to
> submit a file. Does anybody knows how to make it?
>
> Do I need a library such that libwww-perl to do that?
>
> thanks,
>
> Maël



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

Date: 21 May 2003 15:11:44 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Install/setup Net::SSH::PERL
Message-Id: <slrnbcn50h.p3a.randy@theoryx5.uwinnipeg.ca>

On Wed, 7 May 2003 11:44:04 +1000, Sisyphus <kalinabears@hdc.com.au> wrote:
>
>"Anand Ramamurthy" <anand_ramamurthy@yahoo.com> wrote in message
>news:761041e6.0305061050.17cd5e54@posting.google.com...
>> I am trying to install Net::SSH::PERL in Windows 2000 & Windows XP.
>> Net::Telnet is working fine for me.
>
>Quackie's advice is probably the way to go. (You might need to 
>append '.ppd' to the 'ppm install...' line he provided.)
>
>The Win32 version supports only one of the SSH protocols (SSH2 iirc).
>Support of SSH1 is on the author's todo list, but has not yet been done
>afaik.
>And there's no Net::SSH::W32Perl available for perl 5.8.
>
>So, if you need SSH1 support (or are running perl 5.8), you're currently on
>your own. To that end, I can however provide Math::GMP binaries for Win32
>(both perl 5.8 and perl 5.6). You can find them at:
>http://robgil.hypermart.net/w32perl/math_gmp.html
>
>The 'soulcage' site has a ppm of Math::Pari for 5.6, and I can provide 
>one for perl 5.8 (if needed). There's a bug or 2 in Math::Pari 
>on 5.8 - but hopefully they wouldn't affect you.

I've put up a ppm version of Net::SSH::W32Perl under
http://theoryx5.uwinnipeg.ca/ppms/, which hopefully will
also install all its dependencies. As with the perl 5.6 version, 
this only has support for SSH2. I also saw this bug in Math::Pari
on 5.8 in one of its tests (an error about a free to a wrong
pool), but as you mention, this doesn't seem to affect 
Net::SSH::W32Perl or its dependencies, at least as far as 
the tests are concerned.

-- 
best regards,
randy kobes


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

Date: Wed, 21 May 2003 17:43:01 GMT
From: "roach_01" <roach@kronic.net>
Subject: NET:SNPP help
Message-Id: <FUOya.92128$N45.1690714@twister.tampabay.rr.com>

Hi all

I've wrote a little web pager cgi app using the NET:SNPP module.

Does anyone know if there is a way to page multiple numbers on ONE
connection? I am paging the same message to 20+ numbers. Right now I'm
looping through an array and making a new connection for every number being
paged. This is slow and im sure the snpp server is'nt too happy. =P

Here's my snippet, if anyone knows how i could do multiple pages on one
connection instead of a new connection for each page..lemme know. THANKS!!!

 ...
foreach my $number ( @pager_number ) {
    $snpp = Net::SNPP->new('snpp.metrocall.com:444', Debug => 1);
    $snpp->send(Pager=>$number, Message => $message1) or do {
    my $error = $snpp->message;
    print "Page to $user FAILED $error";
    };
}

-r




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

Date: Wed, 21 May 2003 10:37:02 -0600
From: "Rodney" <palladium@spinn.net>
Subject: Re: o conf urllist
Message-Id: <vcna8lkvbut951@corp.supernews.com>

"Alan Watson" <waty@powerup.com.au> wrote in message
news:0fKya.487$iv4.4594@news-server.bigpond.net.au...
> I can't seem to reset the default ftp site in CPAN. Can anyone tell me
how?
> I think the command is something like:
>
> o conf urllist
>
> Thanks,
>
> Alan
>
>
o conf shift urllist http://www.theoldserver.org/CPAN/ will remove the
entry.
o conf unshift urlist http://www.cpan.org/CPAN/  to add an entry.

something like that..

HTH
Rod




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

Date: Wed, 21 May 2003 21:20:38 +0530
From: Thens <thens@nospam.com>
Subject: Recursion and Filehandles
Message-Id: <20030521212038.4ab72f51.thens@nospam.com>


 I have a program that reads statements from a text file and processes
 them. Each line in the file can be a command. Based on the command it
 does something and repeats till  it goes to the end  of the file. The
 commands in the file can be INCLUDE which  means it will have to call
 itself  to process all  the  commands in the  file. I  have written a
 script which does that, and I had a problem  with the filehandle. The
 program terminated without   reading line no  :  2 in  the sample.txt
 file. It  terminated   after it "included"    the  sample1 and  then
 exited. I figured out the problem is due to the filehandle and I made
 it local, then it works.  Is this the correct  way of solving this or
 is there an  elegant solution for this. I  have read  somewhere about
 anonymous globs by eval statements. Will they be useful here ? 

Thanks and Regards,
Thens.

#!/usr/local/bin/perl -w
use strict;

my $file = "sample.txt";
processCommands($file);

### Sub to process all the commands in the file ###
sub processCommands {
  my $file = shift;

  local *FILE; # without this it exits at the first include statement.
  open (FILE, $file ) or die "Cannot open $file : $!";
  while ( <FILE> ) {
    chomp;
    s/^\s*//;  # Leading space
    s/\s*$//;  # Trailing space
    
    if (/PRINT/) {
	print;
        next;
    }	    
    if ( /INCLUDE/ ) {
      # get the filename
      my $file = (split(/\s+/, $_))[1];
      processCommands($file);
    }
    
  }
  
  print "Completed processing the file : $file "; 
}


DATA FILES:
----------

sample.txt

INCLUDE sample1
PRINT Thens

sample1
PRINT sample1_line


__



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

Date: Wed, 21 May 2003 16:13:36 +0000 (UTC)
From: veky@cromath.math.hr (Veky)
Subject: Re: Recursion and Filehandles
Message-Id: <bag8jg$kg4$1@bagan.srce.hr>

Dok je Veky citao comp.lang.perl.misc, pod PIDom 24944 (290687 off, 1 to go...),
primijetio je kreaturu zvanu Thens <thens@nospam.com>,
ispod cijih su prstiju izasle (izmedu ostalih) sljedece rijeci:

| exited. I figured out the problem is due to the filehandle and I made
| it local, then it works.  Is this the correct  way of solving this or
| is there an  elegant solution for this.

I don't know whether it's coorect, but it's probably the way I would do
it. So it makes at least two of us... :-)
In recursive subs (which yours certainly is), it is natural to hold
particular variables on stack, push them on each call, and pop them just
before return... Perl provides such a stack for you, via local ...

| I  have read  somewhere about
| anonymous globs by eval statements. Will they be useful here ? 

Probably not. They are probably for executing _perl_ statements in
file... if I got the idea right.

-- 
\#{%	Sad gradi svoj grad iz snova... znaj da mozes i znaj da znas...


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

Date: 21 May 2003 17:41:15 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Recursion and Filehandles
Message-Id: <u91xys2qxg.fsf@wcl-l.bham.ac.uk>

Thens <thens@nospam.com> writes:

 [ FAQ: "How can I make a filehandle local to a subroutine?" ]

 [ Solution using "local *FILE" as per FAQ ]

>  ...is there an  elegant solution for this.

The elegant solution (autovivification) appeared in (or before Perl
5.6.1) but it did make it into the FAQ in that version.

If you look at the answer in the current version of the FAQ or the
version that ships with 5.8.0 it shows the new elegant solution.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 21 May 2003 19:07:23 +0200
From: "Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Recursion and Filehandles
Message-Id: <3ecbba4f.0@juno.wiesbaden.netsurf.de>

DQoiVGhlbnMiIDx0aGVuc0Bub3NwYW0uY29tPiB3cm90ZS4uLg0KPiANCj4gIEkgaGF2ZSBhIHBy
b2dyYW0gdGhhdCByZWFkcyBzdGF0ZW1lbnRzIGZyb20gYSB0ZXh0IGZpbGUgYW5kIHByb2Nlc3Nl
cw0KPiAgdGhlbS4gRWFjaCBsaW5lIGluIHRoZSBmaWxlIGNhbiBiZSBhIGNvbW1hbmQuIEJhc2Vk
IG9uIHRoZSBjb21tYW5kIGl0DQo+ICBkb2VzIHNvbWV0aGluZyBhbmQgcmVwZWF0cyB0aWxsICBp
dCBnb2VzIHRvIHRoZSBlbmQgIG9mIHRoZSBmaWxlLiBUaGUNCj4gIGNvbW1hbmRzIGluIHRoZSBm
aWxlIGNhbiBiZSBJTkNMVURFIHdoaWNoICBtZWFucyBpdCB3aWxsIGhhdmUgdG8gY2FsbA0KPiAg
aXRzZWxmICB0byBwcm9jZXNzIGFsbCAgdGhlICBjb21tYW5kcyBpbiB0aGUgIGZpbGUuIEkgIGhh
dmUgd3JpdHRlbiBhDQo+ICBzY3JpcHQgd2hpY2ggZG9lcyB0aGF0LCBhbmQgSSBoYWQgYSBwcm9i
bGVtICB3aXRoIHRoZSBmaWxlaGFuZGxlLiBUaGUNCj4gIHByb2dyYW0gdGVybWluYXRlZCB3aXRo
b3V0ICAgcmVhZGluZyBsaW5lIG5vICA6ICAyIGluICB0aGUgc2FtcGxlLnR4dA0KPiAgZmlsZS4g
SXQgIHRlcm1pbmF0ZWQgICBhZnRlciBpdCAiaW5jbHVkZWQiICAgIHRoZSAgc2FtcGxlMSBhbmQg
IHRoZW4NCj4gIGV4aXRlZC4gSSBmaWd1cmVkIG91dCB0aGUgcHJvYmxlbSBpcyBkdWUgdG8gdGhl
IGZpbGVoYW5kbGUgYW5kIEkgbWFkZQ0KPiAgaXQgbG9jYWwsIHRoZW4gaXQgd29ya3MuICBJcyB0
aGlzIHRoZSBjb3JyZWN0ICB3YXkgb2Ygc29sdmluZyB0aGlzIG9yDQo+ICBpcyB0aGVyZSBhbiAg
ZWxlZ2FudCBzb2x1dGlvbiBmb3IgdGhpcy4gSSAgaGF2ZSByZWFkICBzb21ld2hlcmUgYWJvdXQN
Cj4gIGFub255bW91cyBnbG9icyBieSBldmFsIHN0YXRlbWVudHMuIFdpbGwgdGhleSBiZSB1c2Vm
dWwgaGVyZSA/IA0KDQpJIGRvbid0IHRoaW5rIGxvY2FsaXppbmcgYSBmaWxlaGFuZGxlIHRvIGJl
IHVuZWxlZ2FudCwgYnV0IEkgd291bGQgcHJvYmFibHkgdXNlIHRoZSBGaWxlSGFuZGxlIG1vZHVs
ZSB0byBnZXQgcHJvcGVyIGxleGljYWwgZmlsZWhhbmRsZXMgYXMgaW46DQoNCnN1YiBwcm9jZXNz
Q29tbWFuZHMgew0KICBteSAkZmlsZSA9IHNoaWZ0Ow0KDQogIG15ICRmaCA9IEZpbGVIYW5kbGUt
Pm5ldygkZmlsZSkgb3IgZGllICJDYW5ub3Qgb3BlbiAkZmlsZSA6ICQhIjsNCg0KICB3aGlsZSAo
IDwkZmg+ICkgew0KDQogIC4uLg0KDQoNClt1bnRlc3RlZF0NCg0KVGhvbWFz



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

Date: Thu, 22 May 2003 01:17:19 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Shutting Down Windoze
Message-Id: <pan.2003.05.21.15.17.19.898385@bigpond.com>

Does anyone know how to shutdown windoze ?

In LINUX I use "shutdown -h now"

Cheers 

www.tech-software.net


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

Date: Wed, 21 May 2003 16:08:00 +0000 (UTC)
From: veky@cromath.math.hr (Veky)
Subject: Re: Shutting Down Windoze
Message-Id: <bag890$9h4$1@bagan.srce.hr>

Dok je Veky citao comp.lang.perl.misc, pod PIDom 24944 (290682 off, 2 to go...),
primijetio je kreaturu zvanu "Andrew Rich" <andrew.rich@bigpond.com>,
ispod cijih su prstiju izasle (izmedu ostalih) sljedece rijeci:

|Does anyone know how to shutdown windoze ?

yes.

|In LINUX I use "shutdown -h now"

In Windows you usually click around... :-)
but you can use some user32.dll system call, in form of
exec"rundll32 user32.dll ExitWindowsEx,1"... or something like that.

-- 
\#{%	Sad gradi svoj grad iz snova... znaj da mozes i znaj da znas...


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

Date: 21 May 2003 17:40:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Shutting Down Windoze
Message-Id: <u94r3o2qz3.fsf@wcl-l.bham.ac.uk>

"Andrew Rich" <andrew.rich@bigpond.com> writes:

> Does anyone know how to shutdown windoze ?
> 
> In LINUX I use "shutdown -h now"

You appear to have wandered into the wrong newsgroup.

This is a newsgroup about the Perl programming language.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 21 May 2003 17:00:24 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Shutting Down Windoze
Message-Id: <Xns9382844FD7438dkwwashere@216.168.3.30>

Andrew Rich <andrew.rich@bigpond.com> wrote:

> Does anyone know how to shutdown windoze ?
> 
> In LINUX I use "shutdown -h now"

If you want to do this from a Perl program, try looking in the docs for 
the Win32 module. (Assuming you're using the Activestate port.  Dunno 
about Indigoperl)

If you don't want to do this from a Perl program, then you're in the 
wrong newsgroup.


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

Date: Thu, 22 May 2003 01:09:59 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Re: The n'th character of a string
Message-Id: <pan.2003.05.21.15.09.59.905120@bigpond.com>

> print substr( "derek", 2, 1 );

seems right, that is what i have been using 


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

Date: Wed, 21 May 2003 15:27:43 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: The n'th character of a string
Message-Id: <PVMya.22326$OB5.8481830@news4.srv.hcvlny.cv.net>


"Derek Fountain" <nomail@hursley.ibm.com> wrote in message
news:3ecb8748$0$31519$5a62ac22@freenews.iinet.net.au...
> Someone just asked me how to find print the n'th character of a given
> string. I immediately thought along the lines of $string{$n} in PHP or
> string[n] in Python, but I couldn't come up with the Perl equivalent.
>
> I satisfied the asker with either:
>
> print substr( "derek", 2, 1 );
>
> or
>
> print( (split(//,"derek"))[2] );
>
> to pick out the 'r', but I can't help thinking I've missed something.
Is
> there a simple syntax for a getting a single character from a string
given
> the index?

You could also use a regex.
 print "derek"=~/^.{2}(.)/;

I prefer your substr solution for clarity.

Bill






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

Date: Wed, 21 May 2003 16:05:29 +0000 (UTC)
From: veky@cromath.math.hr (Veky)
Subject: Re: The n'th character of a string
Message-Id: <bag849$8sn$1@bagan.srce.hr>

Dok je Veky citao comp.lang.perl.misc, pod PIDom 24944 (290668 off, 3 to go...),
primijetio je kreaturu zvanu Derek Fountain <nomail@hursley.ibm.com>,
ispod cijih su prstiju izasle (izmedu ostalih) sljedece rijeci:

|print substr( "derek", 2, 1 );
|or
|print( (split(//,"derek"))[2] );
|
|to pick out the 'r', but I can't help thinking I've missed something. Is
|there a simple syntax for a getting a single character from a string given
|the index?

No there is not. What could (/should) be simpler than substr :-?

-- 
\#{%	Sad gradi svoj grad iz snova... znaj da mozes i znaj da znas...


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

Date: Thu, 22 May 2003 02:00:57 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: What does this mean ?
Message-Id: <pan.2003.05.21.16.00.56.927916@bigpond.com>

I saw in a previous post this code:-

my ($epoch_sec, $nsec, $nrexmit, $timeout, $ip_addr) = $line 
=~ /^(\d+):(\d+).*rexmits (\d+), timeout (\d+) ms, destined for ([\w|\.]+)/;

I am having troubles seeing where they got 5 values for the second line,
is the seperator a comma, or am I missing something ?

Cheers 

Andy 

www,tech-software.net


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

Date: Wed, 21 May 2003 16:15:59 +0000 (UTC)
From: veky@cromath.math.hr (Veky)
Subject: Re: What does this mean ?
Message-Id: <bag8nv$lub$1@bagan.srce.hr>

Dok je Veky citao comp.lang.perl.misc, pod PIDom 24944 (290688 off, 0 to go...),
primijetio je kreaturu zvanu "Andrew Rich" <andrew.rich@bigpond.com>,
ispod cijih su prstiju izasle (izmedu ostalih) sljedece rijeci:

|my ($epoch_sec, $nsec, $nrexmit, $timeout, $ip_addr) = $line 
|=~ /^(\d+):(\d+).*rexmits (\d+), timeout (\d+) ms, destined for ([\w|\.]+)/;
|
|I am having troubles seeing where they got 5 values for the second line,
|is the seperator a comma, or am I missing something ?

Yes, you're missing something. :-)
See "capturing paretheses" somewhere in regexps explained...
shortly, every pair () captures anything between... and stores it into
the list, which is then assigned to ($epoch,...) . Clearer:-?

-- 
\#{%	Sad gradi svoj grad iz snova... znaj da mozes i znaj da znas...


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

Date: Wed, 21 May 2003 17:22:34 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: What does this mean ?
Message-Id: <20030521172234.21159f5c.john.thetenant-s@moving-picture.com>

On Thu, 22 May 2003 02:00:57 +1000
"Andrew Rich" <andrew.rich@bigpond.com> wrote:
>
> I saw in a previous post this code:-
> 
> my ($epoch_sec, $nsec, $nrexmit, $timeout, $ip_addr) = $line 
> =~ /^(\d+):(\d+).*rexmits (\d+), timeout (\d+) ms, destined for ([\w|\.]+)/;
> 
> I am having troubles seeing where they got 5 values for the second line,
> is the seperator a comma, or am I missing something ?
> 
> Cheers 
> 
> Andy 
> 
> www,tech-software.net

the five values are captured within the five sets of parentheses.
the commas have no special meaning within the regexp.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Thu, 22 May 2003 02:31:25 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Re: What does this mean ?
Message-Id: <pan.2003.05.21.16.31.23.776909@bigpond.com>

Ok I worked it out

1053320039:143483 REXMIT 2188605148 rexmits 1, timeout 278 ms,destined for 140.229.17.222

run thru this

$line =~ tr/a-zA-Z,//d; # truncate, look for a-z or A-Z or a comma 

gives:-

1053320039:143483 2188605148 1 278 140.229.17.222

and 

split (/ +/, $line);

gives you each number 

easy really ;-)

Andrew




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

Date: 21 May 2003 17:40:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: What does this mean ?
Message-Id: <u97k8k2qzj.fsf@wcl-l.bham.ac.uk>

"Andrew Rich" <andrew.rich@bigpond.com> writes:

> Subject: What does this mean ?

It means you didn't put enough effort into composing your subject
line.

> I saw in a previous post this code:-
> 
> my ($epoch_sec, $nsec, $nrexmit, $timeout, $ip_addr) = $line 
> =~ /^(\d+):(\d+).*rexmits (\d+), timeout (\d+) ms, destined for ([\w|\.]+)/;
> 
> I am having troubles seeing where they got 5 values for the second
> line,

Count the opening parentheses.

For further information about Perl regular expressions read the
section of the manual entitled "Perl regular expressions".

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 21 May 2003 17:31:02 +0100
From: "John Dwyer" <johndwyer@primemail.com>
Subject: worth a look
Message-Id: <CQNya.887$aK.873@newsfep3-gui.server.ntli.net>

Hi all,

   I'm looking for free webcam software, which I'm going to install
 on a number of computers in an Internet cafe. I'd like to know what
 you guys would recommend as good stable software, that works well and
 won't crash my computers.
 
   Basically I've narrowed it down to two:
(both of which I found at download.com)

http://download.com.com/3000-2348-10194077.html?tag=lst-0-21
Magellan - This is a big download, but it seems to be
stable, and it lists your cam on the site http://www.eyespyfx.com
so you can find it again. It seems to do recording, and Dial up
(whatever that is :)!)

http://download.com.com/300440-2248-1023194077.html?tag=lst-0-21
CamReady by http://www.CamReady Inc.com/ - Sort of a novel little webcam application. It runs
in the background so you don't know it's running. You press 'tell
a freind' and it sends an email with your IP address in it.

   I'd love to hear back from you all to say wheter one is better
than the other. Download them, and I'd like to see if they are
stable and reliable enough. Just tell me what you think.

   Kindest Regards
   
   John D.






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

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.  

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


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