[25223] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7468 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 1 00:06:02 2004

Date: Tue, 30 Nov 2004 21:05:08 -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, 30 Nov 2004     Volume: 10 Number: 7468

Today's topics:
        [newbie] IO::Socket::INET <dontmewithme@got.it>
    Re: [newbie] IO::Socket::INET <uri@stemsystems.com>
        [OT] Re: SQLite - problem connecting to database (or do <1usa@llenroc.ude.invalid>
        FAQ 5.15: Is there a leak/bug in glob()? <comdog@panix.com>
    Re: looking for simple code to build a search engine <nospam@bigpond.com>
        make this more efficient? <joey01@cfl.rr.com>
    Re: make this more efficient? <jkeen_via_google@yahoo.com>
    Re: make this more efficient? <tadmc@augustmail.com>
        parse tr socket $buf dogdog@noemail.com
    Re: parse tr socket $buf <tadmc@augustmail.com>
    Re: Passing huge double arrays in XML-RPC <tadmc@augustmail.com>
    Re: perl trim function (Anno Siegel)
        print question dogdog@noemail.com
    Re: print question <spamtrap@dot-app.org>
    Re: print question <tadmc@augustmail.com>
    Re: Question about implementing range operator with str bayxarea-usenet@yahoo.com
        split function syntax (Mostafa)
    Re: split function syntax <spamtrap@dot-app.org>
    Re: split function syntax <1usa@llenroc.ude.invalid>
    Re: split function syntax <tadmc@augustmail.com>
    Re: SQLite - problem connecting to database (or doing a <nospam@nospam.com>
    Re: System command <uri@stemsystems.com>
    Re: System command <tadmc@augustmail.com>
    Re: System command <spamtrap@dot-app.org>
    Re: System command <uri@stemsystems.com>
    Re: Trying to understand Perl <tadmc@augustmail.com>
    Re: Trying to understand Perl <parv_@yahooWhereElse.com>
    Re: Trying to understand Perl <tadmc@augustmail.com>
    Re: Trying to understand Perl <parv_@yahooWhereElse.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 01 Dec 2004 02:15:09 GMT
From: Larry <dontmewithme@got.it>
Subject: [newbie] IO::Socket::INET
Message-Id: <dontmewithme-ECD7AC.03150301122004@twister1.tin.it>

Hello

I've a question about perl socket

I'm on MacOS9 running Macperl5.6,I'm connected to the internet via adsl 
lan (dynamic ip)

Below the "server" code I've been working on:

[code]
#!/perl
#
# Server

use strict;
use warnings;
use IO::Socket::INET;

my $server = IO::Socket::INET->new(LocalPort => '6362',
                                   Type      => SOCK_STREAM,
                                   Reuse     => 1,
                                   Listen    => 1 ) || die "$!\n";

while ( my $client = $server->accept() ) {

   print $client "The time is now: " . scalar(localtime(time())) . "\n";
   close $client;
      
}

close($server);                            
[/code]

It does work fine!

Below the "Client" code I've uploaded on my netfirms host:

[code]
#!/perl
#
# Client

use strict;
use warnings;
use IO::Socket::INET;
use CGI::Carp "fatalsToBrowser";
use CGI;

my $q = new CGI();

print $q->header();

my $socket = IO::Socket::INET->new(PeerAddr => '80.116.244.30',
                                 PeerPort => '6362',
                                 Proto    => 'tcp') || die "Can't 
connect to: 80.116.244.30 on port: 6362 $!\n";

print $socket "Hi server!\n";

my $answer = <$socket>;
print $answer;

close($socket);
[/code]

Unfortunately when I run the script via browser I get this message: "no 
route to host" ... I don't presently know why!
Far from it,when I run the code above on my Mac setting "PeerAddr" as 
"127.0.0.1" it works quite fine! (I manage to get the "The time is..." 
message from the "server" script!)

Anyone can help me?

ta


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

Date: Wed, 01 Dec 2004 04:09:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: [newbie] IO::Socket::INET
Message-Id: <x7fz2qy7zk.fsf@mail.sysarch.com>

>>>>> "L" == Larry  <dontmewithme@got.it> writes:

  L> Unfortunately when I run the script via browser I get this message: "no 
  L> route to host" ... I don't presently know why!
  L> Far from it,when I run the code above on my Mac setting "PeerAddr" as 
  L> "127.0.0.1" it works quite fine! (I manage to get the "The time is..." 
  L> message from the "server" script!)

that isn't a perl problem. you have no route to that host/port from
where you run the client. probably a firewall or something. maybe the
server box isn't exposed to the net or it has a firewall disallowing
incoming ports (i think osx has that). so check the network config stuff
for the mac first.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 1 Dec 2004 02:39:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: [OT] Re: SQLite - problem connecting to database (or doing a select)
Message-Id: <Xns95B1DC5ED77DFasu1cornelledu@132.236.56.8>

"daniel kaplan" <nospam@nospam.com> wrote in
news:1101866573.612756@nntp.acecape.com: 

> i stand by what i have said before, some people here are upset with me
> cause i won't take their casual insults sitting down. 

Funny ... I have only seen you hurl personal insults. A statement such as 
"You are wrong, as usual" (which Sherm made) is a statement of fact 
because you have so far not succeded in making a factually correct post 
about anything.

On the other hand, the following statement:

   i guess with a name like that i really should forgive
   you for  being a condesending ass....perhaps your parents 
   should have looked through the "names guaranteed to lose 
   your lunch money with" faq? 

<http://groups.google.com/groups?selm=1098640155.622711%
40nntp.acecape.com&output=gplain>

is nothing but a personal insult and it is indicative of a desire to get 
a rise out of people. Yet, people here (myself included) try ignore these 
insults and focus on the programming questions not out of a desire to 
help you but because we want other people who read this group to be able 
to get good information.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 1 Dec 2004 05:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.15: Is there a leak/bug in glob()?
Message-Id: <cojja5$810$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

5.15: Is there a leak/bug in glob()?

    Due to the current implementation on some operating systems, when you
    use the glob() function or its angle-bracket alias in a scalar context,
    you may cause a memory leak and/or unpredictable behavior. It's best
    therefore to use glob() only in list context.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Wed, 01 Dec 2004 13:23:34 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: looking for simple code to build a search engine
Message-Id: <314rpoF3795klU1@individual.net>

Marcel wrote:

> Hi,
> I have a hobby website with many, many pages with pictures on which I want
> to install a search engine. The ones I've had a look at don't exactly do
> what I want. So I want to make it myself. On the other hand, I'm
> completely new to Perl - it does work fine on my computer though.
> My idea is as follows:
> any search on my website looks into a file (search.txt) of which each line
> looks something like "url= .... thumb= ... title= .... keywords= ...".
> The keywords-part (of course) must be scanned, and if a match is found,
> then the title, url and thumbnail must be returned to the search page.
> The search.txt is fed by my pictures database.
> Is there something out there that I can use?
> Many thanks,
> Marcel


For Perl search engines for a single website look at

http://www.htdig.org/ (I use this myself)
http://swish-e.org/
http://www.xav.com/scripts/search/ (used this in the past)

gtoomey


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

Date: Wed, 01 Dec 2004 01:26:05 GMT
From: "roach" <joey01@cfl.rr.com>
Subject: make this more efficient?
Message-Id: <N49rd.86115$8G4.36404@tornado.tampabay.rr.com>

Is there a more efficient way to do the following code? I tryed reading the
file into an array then working with it,  but this is what i came up with.
For this to work i need to execute it and direct it to an output file like
 ./code.pl > FS.new
I'd appreciate any pointers. Thanks

#!/usr/bin/perl

open (fs, "FS")|| die "can't open file";
open (fsnew, ">FSYUTBLU.test")|| die "can't open file";

while (<fs>) {
s/(.{144})/$1\n/g,$_; #insert newline every 144 chars in the file FS
print (fsnew);
}

close(fsnew);

open(fsnew,"FSYUTBLU.test");

while (<fsnew>) {

            $switches = substr($_,70,60);

            if ($switches eq
"NNNRRRNRRNRRNNNNNNNNRRNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN") {

                        $level = "8";
            }
            elsif ($switches eq
"NNNNNWNWWWNNNNNWNNNNRNNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN") {

                        $level = "7";
            }
            elsif ($switches eq
"NNNRNWNWWWNNNWWWNNRNRNWNNWNNNNWRRNNNNNNNNNNNNNNNNNRNN0NNRNNN") {

                        $level = "5A";
            }
            elsif ($switches eq
"NNNRNWNWWWNNNNNWNNRNRNWNNWNNNNWRRNNNNNNNNNNNNNNNNNRNN0NNRNNN") {

                        $level = "5B";
            }
            elsif ($switches eq
"NNNRRWNWWWNRNWWWNNRNRRWNNWNNNNWWWNNNNNNNNNNNNNNNNNRNN0NNNNNN") {

                        $level = "4A";
            }
            elsif ($switches eq
"NNNRRWNWWWNWWWWWNNRNRWWNNWNNNNWWWNNNNNNNNNNNNNNNNNRNN0NNWRNN") {

                        $level = "4B";
            }
            elsif ($switches eq
"WNWWWWWWWRWWWWWNNWRNWWWNWWWWWNWRWNNNNNNNNNNNNNNNNNRWW5WWWWWN") {

                        $level = "3";
            }

            else{
            $level = "NONE";
            }

            chomp($_);

            print "$_ $level\n";

}

-r




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

Date: Wed, 01 Dec 2004 02:09:59 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: make this more efficient?
Message-Id: <XJ9rd.2450$_C2.1528@trndny01>

roach wrote:

> Is there a more efficient way to do the following code? 

Define "efficient."  Faster?  Smaller memory footprint?  More 
elegant/perlish code?

I tryed reading the
> file into an array then working with it,  but this is what i came up with.
> For this to work i need to execute it and direct it to an output file like
> ./code.pl > FS.new
> I'd appreciate any pointers. Thanks
> 
> #!/usr/bin/perl
> 
> open (fs, "FS")|| die "can't open file";
> open (fsnew, ">FSYUTBLU.test")|| die "can't open file";
> 
> while (<fs>) {
> s/(.{144})/$1\n/g,$_; #insert newline every 144 chars in the file FS
> print (fsnew);
> }
> 
> close(fsnew);

Are you going to do anything with file FSYUTBLU.test other than what 
follows?  If not, then I don't understand why you need to create a new 
file (much less one with a blank once every 144 lines) in the first 
place.  You could just process your original file line-by-line.

> 
> open(fsnew,"FSYUTBLU.test");
> 
> while (<fsnew>) {

Generally speaking, when doing line-by-line processing of a file, this 
is the place at which you want to chomp the newline.

> 
>             $switches = substr($_,70,60);
> 
>             if ($switches eq
> "NNNRRRNRRNRRNNNNNNNNRRNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN") {
> 
>                         $level = "8";
>

Is $level = "8" likely to be the most frequently observed substring? 
The cases should be in descending order of expected frequency of appearance.

[snip balance]

HTH

Jim Keenan


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

Date: Tue, 30 Nov 2004 21:12:41 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: make this more efficient?
Message-Id: <slrncqqdl9.5of.tadmc@magna.augustmail.com>

roach <joey01@cfl.rr.com> wrote:

> Is there a more efficient way to do the following code? 


Your question is ambiguous, so I'm not going to try and answer it.


> I'd appreciate any pointers. Thanks
> 
> #!/usr/bin/perl

   use warnings;
   use strict;

Ask for all the help you can get!


> open (fs, "FS")|| die "can't open file";


It is recommended that you use UPPER CASE filehandles.

You should include the delimited filename, and the *reason*
for the failure in the diagnostic message.

If you use the low-precedence "or" you can eliminate some punctuation.

You should use single quotes unless you *need* one of the two extra
things that you get with double quotes.

   open FS, 'FS' or die "could not open 'FS'  $!";


> s/(.{144})/$1\n/g,$_; #insert newline every 144 chars in the file FS
                   ^^^
                   ^^^

What is that there for?

What do you think it is doing for you?


> open(fsnew,"FSYUTBLU.test");


You should always, yes *always*, check the return value from open.



>             if ($switches eq
> "NNNRRRNRRNRRNNNNNNNNRRNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN") {
> 
>                         $level = "8";
>             }
>             elsif ($switches eq
> "NNNNNWNWWWNNNNNWNNNNRNNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN") {
> 
>                         $level = "7";
>             }


I'd use a hash instead of chaining if-elsifs:

my %levels = qw(
   NNNRRRNRRNRRNNNNNNNNRRNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN   8
   NNNNNWNWWWNNNNNWNNNNRNNNNWNNNNNNNNNNNNNNNNNNNNNNNNRNN0NNRNNN   7
   ...
);

if (exists $levels{$switches} )
   { $level = $levels{$switches} }
else
   ...  # invalid switches


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


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

Date: Wed, 01 Dec 2004 01:29:06 GMT
From: dogdog@noemail.com
Subject: parse tr socket $buf
Message-Id: <pan.2004.12.01.01.29.08.885228@noemail.com>

I've created some simple socket code to send data to a server and
then read back whats sent back. Something like this...I dont have
it in front of me so forgive on the errors.. i'm doing this from
memory.


read($socket,$buf,100);

What I need to do is somehow tr that $buf line. It gives back
soemthing like this

xxx 123456

I just want the 123456 portion to print to my webpage. How can
I do this in perl and embed it in my script after the read($socket.....

tia
dogdog


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

Date: Tue, 30 Nov 2004 21:22:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: parse tr socket $buf
Message-Id: <slrncqqe8e.5of.tadmc@magna.augustmail.com>

dogdog@noemail.com <dogdog@noemail.com> wrote:


> read($socket,$buf,100);


Wouldn't you like to know if you actually got what you asked for?


   die "couldn't read 100 bytes $!" unless read($socket,$buf,100) == 100;


> What I need to do is somehow tr that $buf line. It gives back
> soemthing like this
> 
> xxx 123456
> 
> I just want the 123456 portion to print to my webpage. 


Then you DON'T want to "tr" it, because tr doesn't do what you want done,
it *tr*ansliterates characters.

You have neglected to tell us what it is about the 123456 portion
that indicates that it is the part you want.

All of the code below gives you the "123456" portion, but probably
won't work with your Real Data...


( all untested )

Delete everything up to the first space character?

   s/[^ ]+ //;
or
   s/.+? //;

Delete leading "x"s and spaces?

   s/^[ x]+//;

Delete everything up to the first "1" character?

   s/[^1]+//;

Delete everthing up to the first digit character?

   s/\D+//;

Delete the first 4 characters?

   s/....//;
or
   substr $_, 0, 4 = '';

Delete everything except the last 6 characters?

   substr $_, 0, length()-6;

The most simple way would be to just print what you want printed:

   print '123456';



Your specification sucks, so my implementation sucks to match.

corollary: spend a bit of effort in devising the problem specification.

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


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

Date: Tue, 30 Nov 2004 18:58:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Passing huge double arrays in XML-RPC
Message-Id: <slrncqq5q3.598.tadmc@magna.augustmail.com>

zapata <zapata@hotmail.com> wrote:

> Any help is appreciated, except RTFM, 


So long then.


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


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

Date: 30 Nov 2004 23:06:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl trim function
Message-Id: <coiud3$r0f$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>   AS> Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:

[...]

>   AS> That's the lack in Perl of an anonymous scalar ref constructor.
> 
> yep.
> 
>   AS> I don't see an attractive alternative to quoting (or $_[ 0] . '' and
>   AS> equivalent).  One could say "... ? my $x = shift : shift;" instead,
>   AS> but that's neither cleaner nor clearer.  Here's a ref-free
>   AS> alternative:
> 
>   AS>     sub trim {
>   AS>         for ( defined wantarray ? my $x = shift : shift ) {
>   AS>             s/^\s+//;
>   AS>             s/\s+$//;
>   AS>             return $_ if defined wantarray;
>   AS>         }
>   AS>     }
> 
> i like it but it took a while for my morning eyes to follow the aliasing
> levels. i never realized that shift kept the same aliasing as $_[0] but
> i rarely use shift on @_ or the aliasing like that.

I think I picked it up on clpm (the behavior of shift and pop, I mean),
years back.  Can be useful, though infrequently since argument-modifying
subs are rare.

>                                                     and we both have the
> duplicate use of wantarray but i don't see any easy way around that.

I do: scratch the second one.  What's the harm in returning $_ to
void context? :)

Anno


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

Date: Wed, 01 Dec 2004 00:56:50 GMT
From: dogdog@noemail.com
Subject: print question
Message-Id: <pan.2004.12.01.00.56.52.196172@noemail.com>

I would like to print the output of a script that I have to a
<form> type textbox. I would like the output to be there so I
can just backspace and then use the cgi script
associated with that textbox to send an update/command 
to a server that I have. Anyone know how this can be done? If
so I'd really like to know.

I already have the perl that works command line so if anyone can
provide a method beyond that listed with the form features 
associated with HTML that would be great too.

tia
dogdog


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

Date: Tue, 30 Nov 2004 22:28:57 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: print question
Message-Id: <V42dnXSDY4HmpzDcRVn-sA@adelphia.com>

dogdog@noemail.com wrote:

> I would like to print the output of a script that I have to a
> <form> type textbox. I would like the output to be there so I
> can just backspace and then use the cgi script
> associated with that textbox to send an update/command 
> to a server that I have. Anyone know how this can be done? If
> so I'd really like to know.

Start with the CGI module. There are lots of tutorials on how to use it, 
beginning with the module author's own:

<http://stein.cshl.org/WWW/software/CGI/>

> I already have the perl that works command line so if anyone can
> provide a method beyond that listed with the form features 
> associated with HTML that would be great too.

If you're looking for general Perl guidance other than its use for CGIs, 
here's a good place to start:

<http://learn.perl.org>

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 30 Nov 2004 21:30:36 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: print question
Message-Id: <slrncqqems.5of.tadmc@magna.augustmail.com>

dogdog@noemail.com <dogdog@noemail.com> wrote:


> use the cgi script
> associated with that textbox

> Anyone know how this can be done? 


Use Perl's print() function to output the proper HTML.


> If
> so I'd really like to know.


You're welcome.


> I already have the perl that works command line so if anyone can
> provide a method beyond that listed 


Errr, there *is no* method listed, so I don't know what you are
talking about there...


> with the form features 
> associated with HTML that would be great too.


This is the Perl newsgroup. We discuss Perl issues here.

You use the print() function to make output with Perl.


What output you should be making depends not on your programming
language, but on the application that you are writing.

They discuss HTML over in the HTML newsgroup:

      comp.infosystems.www.authoring.html


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


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

Date: 30 Nov 2004 17:54:45 -0800
From: bayxarea-usenet@yahoo.com
Subject: Re: Question about implementing range operator with strings
Message-Id: <1101866085.382958.8190@z14g2000cwz.googlegroups.com>

Thanks!



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

Date: 30 Nov 2004 19:24:38 -0800
From: mohammad.munir@gmail.com (Mostafa)
Subject: split function syntax
Message-Id: <c3c09310.0411301924.236c76ee@posting.google.com>

open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
while(<PH>) {
    chomp;
    ($number, $email) = ( split(/\s+/, $_) )[1,2];
    
    $Phone{$number} = $_;
    $Email{$email} = $_;
}
close(PH);
*******************************************************************
i couldn't find what does this expression means in split function
[1,2]

**********************************************************************
i am also including the customers.txt file below
********************************************************************
Smith,John   (248)-555-9430 jsmith@aol.com

Hunter,Apryl  (810)-555-3029 april@showers.org

Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk

Ching,Iris   (305)-555-0919 iching@zen.org

Doe,John     (212)-555-0912 jdoe@morgue.com

Jones,Tom    (312)-555-3321 tj2342@aol.com

Smith,John   (607)-555-0023 smith@pocahontas.com

Crosby,Dave  (405)-555-1516 cros@csny.org

Johns,Pam    (313)-555-6790 pj@sleepy.com

Jeter,Linda  (810)-555-8761 netless@earthlink.net

Garland,Judy (305)-555-1231 ozgal@rainbow.com
***********************************************************************
i guess [1,2 ]somehow saves phone and email column to $number and
$email , nnow if i want to retrive name from the  .txt file , then
should i do like below---
*************************************************************************
open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
while(<PH>) {
    chomp;
    ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];
    $Name{name} = $_;
    $Phone{$number} = $_;
    $Email{$email} = $_;
}
close(PH);
***********************************************************************
i did but it's not working
********************************************************************
any clue?????????


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

Date: Tue, 30 Nov 2004 22:42:24 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: split function syntax
Message-Id: <ytWdnTKPpqY_oDDcRVn-tg@adelphia.com>

Mostafa wrote:

>     ($number, $email) = ( split(/\s+/, $_) )[1,2];
>     
> *******************************************************************
> i couldn't find what does this expression means in split function
> [1,2]

It's called a "slice". split() returns a list, and [1,2] is used to 
return a subset of that list. Specifically, the elements at index 1 and 
2, which are the phone and email.

Have a look at 'perldoc perldata' - there's a section titled "Slices".

> **********************************************************************
> i am also including the customers.txt file below
> ********************************************************************

Amusing names & email addresses, by the way. :-)

> ***********************************************************************
> i guess [1,2 ]somehow saves phone and email column to $number and
> $email , nnow if i want to retrive name from the  .txt file , then
> should i do like below---
> *************************************************************************
> open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
> while(<PH>) {
>     chomp;
>     ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];
>     $Name{name} = $_;
>     $Phone{$number} = $_;
>     $Email{$email} = $_;
> }
> close(PH);
> ***********************************************************************
> i did but it's not working
> ********************************************************************

Define "not working". Since you want all three fields now, you could do 
away with the slice entirely, and simply use:

($name, $number, $email) = split(/\s+/, $_);

You could simplify it further. split() defaults to splitting $_ if no 
other variable is given, and defaults to splitting on white space if no 
other pattern is given. So you could use:

($name, $number, $email) = split;

Finally, it's not directly related to your question, but you *really* 
should be using strict and warnings, and declaring these variables 
properly with "my" or "our" as appropriate. Have you seen the posting 
guidelines that appear here frequently?

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 1 Dec 2004 03:59:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: split function syntax
Message-Id: <Xns95B1E9DD6A3D7asu1cornelledu@132.236.56.8>

mohammad.munir@gmail.com (Mostafa) wrote in 
news:c3c09310.0411301924.236c76ee@posting.google.com:

I don't see

use strict;
use warnings;

> open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
> while(<PH>) {
>     chomp;
>     ($number, $email) = ( split(/\s+/, $_) )[1,2];

my ($number, $email) = ( split(/\s+/, $_) )[1,2];

>     
>     $Phone{$number} = $_;
>     $Email{$email} = $_;
> }
> close(PH);

 ...

> i couldn't find what does this expression means in split function
> [1,2]

 ..

[1,2] is not an argument to the split function. The syntax is for selecting 
array slices. For example:

my @ary = qw(a b c d);
print join "\n", @ary[1,2];

Now, in the code above, you are creating hash tables that allow you to look 
up the full record by phone number and email. I am assuming that is what 
you want but do look at the resulting data structures using Data::Dumper to 
make sure that is indeed what you want.

use strict;
use warnings;

my %Phone;
my %Email;

while(<DATA>) {
    chomp;
    my ($number, $email) = ( split /\s+/, $_ )[1,2];
    $Phone{$number} = $_;
    $Email{$email} = $_;
}

use Data::Dumper;
print Dumper \%Phone, \%Email;

__DATA__
Hunter,Apryl  (810)-555-3029 april@showers.org
Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk
Ching,Iris   (305)-555-0919 iching@zen.org
__END__

C:\Home> ph
$VAR1 = {
 '(405)-555-8710' => 'Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk',
 '(305)-555-0919' => 'Ching,Iris   (305)-555-0919 iching@zen.org',
 '(810)-555-3029' => 'Hunter,Apryl  (810)-555-3029 april@showers.org'
};

$VAR2 = {
 'iching@zen.org' => 'Ching,Iris   (305)-555-0919 iching@zen.org',
 'april@showers.org' => 'Hunter,Apryl  (810)-555-3029 april@showers.org',
 'pats@starfleet.co.uk' => 'Stewart,Pat  (405)-555-8710 
pats@starfleet.co.uk'
};


> i guess [1,2 ]somehow saves phone and email column to $number and
> $email , nnow if i want to retrive name from the  .txt file , then
> should i do like below---

I still don't see:

use strict;
use warnings;

> open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
> while(<PH>) {
>     chomp;
>     ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];

my ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];

Well, this time you don't really need to explicitly select the elements of 
the returned array.

>     $Name{name} = $_;
>     $Phone{$number} = $_;
>     $Email{$email} = $_;
> }
> close(PH);

 ...

> i did but it's not working

That is not a helpful description of the problem you are experiencing. have 
you read the posting guidelines posted here regularly?

use strict;
use warnings;

my %Phone;
my %Email;
my %Name;

while(<DATA>) {
    chomp;
    my ($name, $number, $email) = split /\s+/, $_;
    $Phone{$number} = $_;
    $Email{$email} = $_;
    $Name{$name} = $_;
}

use Data::Dumper;
print Dumper \%Phone, \%Email, \%Name;

__DATA__
Hunter,Apryl  (810)-555-3029 april@showers.org
Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk
Ching,Iris   (305)-555-0919 iching@zen.org
__END__


C:\Home\asu1> ph
$VAR1 = {
  '(405)-555-8710' => 'Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk',
  '(305)-555-0919' => 'Ching,Iris   (305)-555-0919 iching@zen.org',
  '(810)-555-3029' => 'Hunter,Apryl  (810)-555-3029 april@showers.org'
};
$VAR2 = {
  'iching@zen.org' => 'Ching,Iris   (305)-555-0919 iching@zen.org',
  'april@showers.org' => 'Hunter,Apryl  (810)-555-3029 april@showers.org',
  'pats@starfleet.co.uk' => 'Stewart,Pat  (405)-555-8710 
pats@starfleet.co.uk'
};
$VAR3 = {
  'Hunter,Apryl' => 'Hunter,Apryl  (810)-555-3029 april@showers.org',
  'Ching,Iris' => 'Ching,Iris   (305)-555-0919 iching@zen.org',
  'Stewart,Pat' => 'Stewart,Pat  (405)-555-8710 pats@starfleet.co.uk'
};

> any clue?????????

Depending on exactly what you are trying to accomplish, you might benefit 
from using DBI with DBD::CSV.


-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Tue, 30 Nov 2004 22:29:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: split function syntax
Message-Id: <slrncqqi54.5vk.tadmc@magna.augustmail.com>

Mostafa <mohammad.munir@gmail.com> wrote:

>     ($number, $email) = ( split(/\s+/, $_) )[1,2];

> i couldn't find what does this expression means in split function
> [1,2]


See the "Slices" section in:

   perldoc perldata



This should do the same thing and be easier to read:

   ($number, $email) = (split)[1,2];


> i guess [1,2 ]somehow saves phone and email column to $number and
> $email , nnow if i want to retrive name from the  .txt file , then
> should i do like below---

>     ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];


If you want _all_ of the split fields, then there is no need
for any slicing at all:

   ($name, $number, $email) = split;


What if a user has a space character in their name or email address?

   eg: Thorton,Billy Bob


> i did but it's not working

What did you want it to do?

What is it doing instead?

You must provide symptoms if you hope for a diagnosis.


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


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

Date: Tue, 30 Nov 2004 21:01:09 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: SQLite - problem connecting to database (or doing a select)
Message-Id: <1101866573.612756@nntp.acecape.com>

Sherm Pendley" <spamtrap@dot-app.org> wrote in message


>It ain't personal, it's just programming. Stop posting nonsense, and
>I'll stop correcting it. It's admirable that you want to help, but
>misinformation doesn't help anyone.

>>>You thought wrong. As usual.

see, to me, that's a correction, along with an swip....your inability to
stop tpying after you make your point (the first period) is where you take
swipes, and therefore it obviosuly is personal.

> would love to find where you told me about DBD

>>>post here where sherm tells me about DBI and activestate

well you showed me, i did make a post here about Net::POP3, i only mentioned
DBI in that post as it was my control subject....but yes, while i didnt ask
about it, he did tell me about it....so i stand corrected.

>>>This is a *big* part of the reason so many people are upset with you,
>>>by the way. You ask a question, you get some answers. Then you come
>>>back later and ask the same question again. When someone asks you why
>>>you ignored the previous answers, you get mad and start calling them
>>>names.

i stand by what i have said before, some people here are upset with me cause
i won't take their casual insults sitting down.  want to correct me, fine,
want to ignore me, even better......but if you really want to call your self
a teacher one day, you'll either JUST correct me or JUST ignore
me.....otherwise when you take it beyond that, your just some indivisual
with low self-esteem who enjoys being all powerful behind the protection of
a computer screen....and when you lash out, so will i.....

if you have a reply sherm, you'll still need to email me as i finally fixed
the kill/block part on OE newsgroups

later





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

Date: Tue, 30 Nov 2004 23:40:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: System command
Message-Id: <x7ekia29dq.fsf@mail.sysarch.com>

>>>>> "L" == Leon  <eon@hotmail.com> writes:

  >> > >
  >> > @Result = `date`;
  >> 
  >> Why the array? On my system, `date` returns only one line, and I would
  >> do:

  L> Sorry, my mistake, just in habit of using it with system commands
  L> that return more than one line of text as result (can't quite
  L> explain why I then decide to choose `date` in the example:s).

huh? system commands don't return ANY lines of text.

  L> So should obviously be $Result or @Result depending on expected output:)

no. it should be a scalar or an array depending on whether you want the
result of backticks to be a single string or split on newlines. the
actual command and its 'expected output' in the backticks has nothing to
do with it.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 30 Nov 2004 19:03:53 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: System command
Message-Id: <slrncqq63p.598.tadmc@magna.augustmail.com>

Leon <eon@hotmail.com> wrote:
> "Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
> news:301120041232269680%jgibson@mail.arc.nasa.gov...
>> In article <d2%qd.65$FD1.63@newsfe6-win.ntli.net>, Leon
>> <eon@hotmail.com> wrote:

>> > @Result = `date`;
>>
>> Why the array? On my system, `date` returns only one line, and I would
>> do:
> 
> Sorry, my mistake, just in habit of using it with system commands that
> return more than one line of text as result


Please show a system() command that returns more than one line of text 
as result, I have never seen one.


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


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

Date: Tue, 30 Nov 2004 22:24:06 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: System command
Message-Id: <3POdneBNJK_FpDDcRVn-gQ@adelphia.com>

Tad McClellan wrote:

> Leon <eon@hotmail.com> wrote:
> 
>>Sorry, my mistake, just in habit of using it with system commands that
>>return more than one line of text as result
> 
> Please show a system() command that returns more than one line of text 
> as result, I have never seen one.

Uri Guttman wrote:

 > huh? system commands don't return ANY lines of text.

I think you guys missed the point. Leon isn't talking about Perl's 
system() function here. He's referring to his earlier use of 
"@result=`date`" instead of $result=`date`. Varun asked "why the 
array?", since the date command produces only one line of output.

Given the context of his reply, it's pretty obvious that Leon is 
referring to his habit of using arrays to store the result of system 
commands such as 'ls' or 'ps', that produce multiple lines of output.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 01 Dec 2004 04:06:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: System command
Message-Id: <x7is7my85b.fsf@mail.sysarch.com>

>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:

  SP> Tad McClellan wrote:
  >> Leon <eon@hotmail.com> wrote:
  >> 
  >>> Sorry, my mistake, just in habit of using it with system commands that
  >>> return more than one line of text as result
  >> Please show a system() command that returns more than one line of
  >> text as result, I have never seen one.

  SP> Uri Guttman wrote:

  >> huh? system commands don't return ANY lines of text.

  SP> I think you guys missed the point. Leon isn't talking about Perl's
  SP> system() function here. He's referring to his earlier use of
  SP> "@result=`date`" instead of $result=`date`. Varun asked "why the
  SP> array?", since the date command produces only one line of output.

  SP> Given the context of his reply, it's pretty obvious that Leon is
  SP> referring to his habit of using arrays to store the result of system
  SP> commands such as 'ls' or 'ps', that produce multiple lines of output.

i got that point. you should have quoted the second part of my post
where i point out that context determines what happens with backtick
output. and 'ls' and 'ps' have never been called system commands in my
experience. call plain programs or whatever but not system commands.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 30 Nov 2004 19:09:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Trying to understand Perl
Message-Id: <slrncqq6f2.598.tadmc@magna.augustmail.com>

Patrick <psmith@marine.usf.edu> wrote:

> I am trying to understand Perl and why things work. 


Perl comes with lots of documentation covering such things.

Have you looked there yet?


> Could someone break 
> down for me the snippet of code below and tell me exactly how the 
> operation works. 


> (grep {$newfile eq $_} @files)


grep is a function, read about it in:

   perldoc perlfunc

eq is an operatior, read about it in:

   perldoc perlop

$newfile and @files are data, read about them in:

   perldoc perldata

The parenthesis do nothing there, as far as I can tell.

The curlies form a BLOCK of code to execute.


If you still don't understand the code after reading up on all of the
components, then please post again and describe what part you need 
help with.


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


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

Date: Tue, 30 Nov 2004 21:16:28 -0600
From: parv <parv_@yahooWhereElse.com>
Subject: Re: Trying to understand Perl
Message-Id: <slrncqqe22.286.parv_@localhost.holy.cow>

in message <Wa4rd.1965$zK1.85@trndny05>,
wrote Paul Lalli ...

> "Patrick" <psmith@marine.usf.edu> wrote in message
> news:coihi3$p2t$1@news1.usf.edu...
>>
>> (grep {$newfile eq $_} @files)
>
> The C<grep> function takes two arguments.  The first is a block or
> expression that returns a boolean value.  The second is a list of
> elements.

First argument does not need to be a BLOCK, it can be an EXPRession
too.  See more in perldoc(1) about grep & map functions.


> In this case, the first argument is the block { $newfile eq $_ } and
> the second argument is the list of elements contained in @files

In this case, it is indeed a block.


  - parv

-- 
As nice it is to receive personal mail, too much sweetness causes
tooth decay.  Unless you have burning desire to contact me, do not do
away w/ WhereElse in the address for private communication.



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

Date: Tue, 30 Nov 2004 21:50:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Trying to understand Perl
Message-Id: <slrncqqfru.5s0.tadmc@magna.augustmail.com>

parv <parv_@yahooWhereElse.com> wrote:
> in message <Wa4rd.1965$zK1.85@trndny05>,
> wrote Paul Lalli ...

>> The C<grep> function takes two arguments.  The first is a block or
                                                             ^^^^^^^^
>> expression 
   ^^^^^^^^^^

> First argument does not need to be a BLOCK, it can be an EXPRession
> too. 


Errr, that's what Paul said.

You are acting like you are correcting him, what error did he make?


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


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

Date: Tue, 30 Nov 2004 22:30:36 -0600
From: parv <parv_@yahooWhereElse.com>
Subject: Re: Trying to understand Perl
Message-Id: <slrncqqid2.38e.parv_@localhost.holy.cow>

in message <slrncqqfru.5s0.tadmc@magna.augustmail.com>,
wrote Tad McClellan ...

> parv <parv_@yahooWhereElse.com> wrote:
>> in message <Wa4rd.1965$zK1.85@trndny05>,
>> wrote Paul Lalli ...
>
>>> The C<grep> function takes two arguments.  The first is a block or
>                                                              ^^^^^^^^
>>> expression 
>    ^^^^^^^^^^
>
>> First argument does not need to be a BLOCK, it can be an EXPRession
>> too. 
>
> Errr, that's what Paul said.
>
> You are acting like you are correcting him, what error did he make?

Yikes!  My fault!  I completely missed that; somehow "block" blocked
my eyes.


Sorry, Paul (and everybody else).


  - parv

-- 
As nice it is to receive personal mail, too much sweetness causes
tooth decay.  Unless you have burning desire to contact me, do not do
away w/ WhereElse in the address for private communication.



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

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


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