[28819] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 63 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 22 18:15:22 2007

Date: Mon, 22 Jan 2007 15:15:14 -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           Mon, 22 Jan 2007     Volume: 11 Number: 63

Today's topics:
        Pattern Matching and Extraction <doni.sekar@gmail.com>
    Re: Pattern Matching and Extraction <john@castleamber.com>
    Re: Pattern Matching and Extraction <doni.sekar@gmail.com>
    Re: Pattern Matching and Extraction <purlgurl@purlgurl.net>
    Re: Pattern Matching and Extraction <john@castleamber.com>
    Re: Pattern Matching and Extraction <bik.mido@tiscalinet.it>
    Re: Pattern Matching and Extraction <doni.sekar@gmail.com>
    Re: Perl hash and rehash seeds; deterministic hash orde ozgune@gmail.com
    Re: problem GD and my package Random->Random::new <john.swilting@wanadoo.fr>
    Re: problem GD and my package Random->Random::new <glex_no-spam@qwest-spam-no.invalid>
    Re: problems cgi and sendmail <jgibson@mail.arc.nasa.gov>
    Re: problems cgi and sendmail <spamtrap@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Jan 2007 11:51:35 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Pattern Matching and Extraction
Message-Id: <1169495495.531101.319920@q2g2000cwa.googlegroups.com>

Hi,

I am writing a program where based upon an user input, I perform a
pattern match to extract the user input from the file. If there is a
match then I would like to print the 4th and 5th field of the next line
from where the pattern match occured. Can anyone let me know how can I
perform this.

Here is how the data is represented in the file.

Name
->	Address1 Address2 City ZipCode
Name
->	Address1 Address2 City ZipCode
Name
->	Address1 Address2 City ZipCode
Name
->	Address1 Address2 City ZipCode
Name
->	Address1 Address2 City ZipCode

Thanks,
doni



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

Date: 22 Jan 2007 19:56:17 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Pattern Matching and Extraction
Message-Id: <Xns98C08DC867099castleamber@130.133.1.4>

"doni" <doni.sekar@gmail.com> wrote:

> Hi,
> 
> I am writing a program where based upon an user input, I perform a
> pattern match to extract the user input from the file. If there is a
> match then I would like to print the 4th and 5th field of the next line
> from where the pattern match occured. Can anyone let me know how can I
> perform this.

What have you tried so far.

> Here is how the data is represented in the file.
> 
> Name
> ->     Address1 Address2 City ZipCode

Better, post actual data, maybe munged a bit. What's after the ->? A tab, 
a fixed number of spaces? Can an address contain spaces? A city? A 
zipcode? Are the fields fixed width, etc.


-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 22 Jan 2007 12:08:59 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Pattern Matching and Extraction
Message-Id: <1169496539.835136.5130@l53g2000cwa.googlegroups.com>

John,

Here is how the data looks like.

Patrick
->	2345 CountryLane Houston 77023
Craig
->	7200 Archstone Apts, #404 San Ramon 94583
Bret
->	501 TownHouse Apts, #202 Houston 77023
Gilbert
->	4200 OakView Apts, #6, Nashua 03060

So, if the user inputs "Patrick" I should be able to match Patrick in
the data file and then print "Houston" and "77023".

Thanks,
doni

John Bokma wrote:
> "doni" <doni.sekar@gmail.com> wrote:
>
> > Hi,
> >
> > I am writing a program where based upon an user input, I perform a
> > pattern match to extract the user input from the file. If there is a
> > match then I would like to print the 4th and 5th field of the next line
> > from where the pattern match occured. Can anyone let me know how can I
> > perform this.
>
> What have you tried so far.
>
> > Here is how the data is represented in the file.
> >
> > Name
> > ->     Address1 Address2 City ZipCode
>
> Better, post actual data, maybe munged a bit. What's after the ->? A tab,
> a fixed number of spaces? Can an address contain spaces? A city? A
> zipcode? Are the fields fixed width, etc.
>
>
> --
> John                Experienced Perl programmer: http://castleamber.com/
>
>           Perl help, tutorials, and examples: http://johnbokma.com/perl/



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

Date: Mon, 22 Jan 2007 14:29:10 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Pattern Matching and Extraction
Message-Id: <45B53AB6.80906@purlgurl.net>

doni wrote:

> John,

> Patrick
> ->	2345 CountryLane Houston 77023
> Craig
> ->	7200 Archstone Apts, #404 San Ramon 94583

> So, if the user inputs "Patrick" I should be able to match Patrick in
> the data file and then print "Houston" and "77023".

Impossible. You cannot extract a city name nor much of
the remaining data. You have no viable delimiters. You
can pull the numerical part of an address at the beginning
of a line, you can pull the zip code. Nothing else, though.

Only way you can accomplish your task is to pattern match
known city names against what is in your file. This would
an exceptionally inefficient approach.

Format your input data using common sense.

Patrick:2345 Country Lane:Houston:77023
Craig:7200 Archstone Apts, #404:San Ramon:94583

Purl Gurl




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

Date: 22 Jan 2007 22:53:27 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Pattern Matching and Extraction
Message-Id: <Xns98C0ABD1EE34Dcastleamber@130.133.1.4>

"doni" <doni.sekar@gmail.com> wrote:

> John,
> 
> Here is how the data looks like.
> 
> Patrick
> ->     2345 CountryLane Houston 77023
> Craig
> ->     7200 Archstone Apts, #404 San Ramon 94583
> Bret
> ->     501 TownHouse Apts, #202 Houston 77023
> Gilbert
> ->     4200 OakView Apts, #6, Nashua 03060

Don't top post (if you don't know what that means, use Google to look it 
up).

If you can change your data format I recommend to do so. I can give you a 
regexp that matches the 2nd line, but it might fail for data you and I 
don't expect at this stage.

Use CSV or XML and a module that can handle data in the format you choose.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Mon, 22 Jan 2007 23:59:54 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Pattern Matching and Extraction
Message-Id: <fcfar2debna6444d9qf4jku71h0cs8en1m@4ax.com>

On 22 Jan 2007 12:08:59 -0800, "doni" <doni.sekar@gmail.com> wrote:

>Here is how the data looks like.
>
>Patrick
>->	2345 CountryLane Houston 77023
>Craig
>->	7200 Archstone Apts, #404 San Ramon 94583
>Bret
>->	501 TownHouse Apts, #202 Houston 77023
>Gilbert
>->	4200 OakView Apts, #6, Nashua 03060
>
>So, if the user inputs "Patrick" I should be able to match Patrick in
>the data file and then print "Houston" and "77023".

Something like the following may come close:
  
  while (<$fh>) {
      chomp;
      next unless $_ eq 'Patrick';
      defined($_=<$fh>) or last;
      print "@{[ (split)[-2,-1] ]}";
  }

Of course in "real" code you would add some check, in particular you
would make sure that the fields got from split() are defined and
consistent with what you expect them to be like. OTOH your "format"
seems inconsistent: it's partly comma separated, partly space
separated, and differently so on different lines. Moreover some city
name seem to include space(s). Thus it's hard to say what one should
really split() on.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 22 Jan 2007 15:02:11 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Pattern Matching and Extraction
Message-Id: <1169506931.107344.47920@l53g2000cwa.googlegroups.com>

John,
I cannot change the format as the generated file has data in that
format. I will take a look at using CSV or XML for handling my data
format.
If you can point me to any example that uses CSV or XML that handles
these kinds of data formats, it will be really helpful.

Thanks,
doni



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

Date: 22 Jan 2007 11:58:06 -0800
From: ozgune@gmail.com
Subject: Re: Perl hash and rehash seeds; deterministic hash ordering
Message-Id: <1169495886.857884.23650@q2g2000cwa.googlegroups.com>

Thanks, that clears it; I wrongfully thought the original post on the
issue (Patch #22371) cited the final implementation behavior.

In summary, Perl gives no guarantees about the ordering of an hash's
key value pairs, and documents this behavior. Perl 5.8.8's
implementation will give a deterministic order until the hash split
can't redistribute the entries evenly. (More specifically, after a
split, if the longest chain in the hash still has a lot of entries,
Perl switches to random seeds.)

Ozgun.

Bo Lindbergh wrote:
> There's a flag in each hash that controls whether the random or the
> non-random hash seed is used.  Hashes start out non-random and switch to
> random if and when the hsplit function thinks it's a good idea.  Search for
> "Pathological data" in hv.c for the details.
> 
> /Bo Lindbergh



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

Date: Mon, 22 Jan 2007 18:42:42 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: problem GD and my package Random->Random::new
Message-Id: <45b4f78a$0$5104$ba4acef3@news.orange.fr>

anno4000@radom.zrz.tu-berlin.de wrote:

> Mark Clements  <mark.clementsREMOVETHIS@wanadoo.fr> wrote in
> comp.lang.perl.misc:
>> john.swilting wrote:
> 
>> > its $text = Random->Random::new
> 
>> By the way, the constructor would normally be something like:
>> 
>> my $random_obj = Random->new();
>>
>> Although your syntax appears to work, I've never seen it done like that
>> before.
> 
> You can always qualify a method with a class name.  That makes sure
> inheritance starts at that point.  You can even specify an entirely
> unrelated class:
> 
>     One->Other::new( ...);
> 
> would call the method Other::new (or a method named ->new in one of
> Other's base classes) with the invocant One.  A normal ->new method
> would then initialize an object of its own kind with the parameters
> given, but bless it into class One.
> 
> The technique does occasionally make sense, though not in the OPs case.
> 
> Anno

use my code
$test = Random->new();
I have to make what to return him(it) better
my code package
#!/use/bin/perl -w

package Random;

use strict;
require Exporter;

use vars qw( @ISA);

##$VERSION = O.O1;

@ISA = qw(Exporter);

sub new {
    my $class=shift;
    my $self={};
    bless $self,$class;

my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
            '16','17','18','19','20','21','22','23','24','25','26','27','28',
            '29','30','31','32','33','34','35','36','37','38','39','40','41',
            '42','43','44','45','46','47','48','49','50','a','b','c','d','e',
            'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
             'v','w', 'x','y','z','A','B','C','D','E','F','G','H','I','J','K',
             'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
    $self="";
    my$self1="";
    my$self2="";
    my$self3="";
    my$self4="";
        $self1.=$liste[int rand@liste];
    $self .= $self1;
        $self2.=$liste[int rand@liste];
    $self .=$self2;
        $self3.=$liste[int rand@liste];
    $self .=$self3;
        $self4.=$liste[int rand@liste];
    return $self;
    }


END {}
1;



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

Date: Mon, 22 Jan 2007 13:36:13 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: problem GD and my package Random->Random::new
Message-Id: <45b511a7$0$10296$815e3792@news.qwest.net>

john.swilting wrote:

> my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
[...]
>             '104','105','106','107','108','109','110');

You can make that much shorter..
push( @liste, 1 .. 110);



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

Date: Mon, 22 Jan 2007 09:52:27 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: problems cgi and sendmail
Message-Id: <220120070952273011%jgibson@mail.arc.nasa.gov>

In article <45b2fbdf$0$27401$ba4acef3@news.orange.fr>, john.swilting
<john.swilting@wanadoo.fr> wrote:

> Why the e-mail is not to send
> Why on every page he indicates to me No recipient addresses found in header
> 
> my code
> #!/usr/bin/perl -w
> 
> use strict;
> use CGI qw(:standard escapeHTML);
> use CGI::Carp qw(fatalsToBrowser);
> 
> my %Etats;
> my @liste_param;
> my $Ecran_actuel;
> 
> ## hachage des documents et des fonctions
> 
> %Etats = (
>         'Défaut' =>\&document_de_garde,
>         'Chemises' =>\&chemise,
>         'Chaussures' =>\&chaussures,
>         'Passage à la caisse' =>\&passage_a_la_caisse,
>         'Carte' =>\&carte_de_credit,
>         'Commande' =>\&commande,
>         'Annnulation' =>\&document_de_garde,
> );
> 
> $Ecran_actuel = param(".Etat") || "Défaut";
> die "Pas d'écran pour $Ecran_actuel" unless $Etats{$Ecran_actuel};
> 
> ## engendre le document courant
> 
> en_tete_standard();
> 
> while ( my ($nom_ecran,$fonction) = each %Etats){
>         $fonction->($nom_ecran eq $Ecran_actuel);
>    
> }
>  open(COURRIER, "|/usr/lib/sendmail -oi -t")
>       or die "fork de sendmail impossible : $!";
>     print COURRIER <<EOF;
>     From: $0(votre script cgi)
>     To:john.swilting\@wanadoo.fr
>     Subject: soumission de formulaire par courrier electronique
>     
[rest of program snipped]

Try starting the header lines in column 1.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Mon, 22 Jan 2007 14:13:57 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: problems cgi and sendmail
Message-Id: <m2y7nu27t6.fsf@Sherm-Pendleys-Computer.local>

Jim Gibson <jgibson@mail.arc.nasa.gov> writes:

> In article <45b2fbdf$0$27401$ba4acef3@news.orange.fr>, john.swilting
> <john.swilting@wanadoo.fr> wrote:
>
>>  open(COURRIER, "|/usr/lib/sendmail -oi -t")
>>       or die "fork de sendmail impossible : $!";
>>     print COURRIER <<EOF;
>>     From: $0(votre script cgi)
>>     To:john.swilting\@wanadoo.fr
>>     Subject: soumission de formulaire par courrier electronique
>>     
> [rest of program snipped]
>
> Try starting the header lines in column 1.

Quite right - email headers *must* be flush left.

Also, have a look at 'perldoc perlfaq4', the question "Why don't my <<HERE
documents work?" for recipes that allow you to indent your <<HERE documents
in your Perl code, and still get output that's flush left.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

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 V11 Issue 63
*************************************


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