[22616] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4837 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 12 14:05:54 2003

Date: Sat, 12 Apr 2003 11:05:06 -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           Sat, 12 Apr 2003     Volume: 10 Number: 4837

Today's topics:
    Re: DBI and binding [attempt 2] <wksmith@optonline.net>
    Re: DBI and binding <mbudash@sonic.net>
        Dynamic loading of modules <arevos@arevol.co.uk>
    Re: Dynamic loading of modules <me@privacy.net>
        IO::Socket and  IPv6 ? <webmaster@neverseenbefore.com>
        LWP Problem with 500 (Internal Server Error) Can't read (Chacrint Charinthorn)
    Re: LWP Problem with 500 (Internal Server Error) Can't  <rereidy@indra.com>
        match identical lines of file. (supportgeek)
    Re: match identical lines of file. <bwalton@rochester.rr.com>
    Re: match identical lines of file. <Jodyman@hotmail.com>
        Newline problem <kasp@epatra.com>
    Re: Newline problem <mbudash@sonic.net>
    Re: Newline problem <kasp@epatra.com>
        problem with Term::ReadKey <spamtrap@lapsley.ukshells.co.uk>
    Re: Search for text than search again based on results. (supportgeek)
    Re: Search for text than search again based on results. (supportgeek)
    Re: Search for text than search again based on results. <mbudash@sonic.net>
    Re: Search for text than search again based on results. <wksmith@optonline.net>
        split question (Bruno Skorepa)
    Re: split question <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 12 Apr 2003 16:44:20 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: DBI and binding [attempt 2]
Message-Id: <EnXla.49642$Xd1.16566357@news4.srv.hcvlny.cv.net>


"Bigus" <bigus NO @ SPAM creationfactor .net> wrote in message
news:zbHla.214$FA6.4254@newsfep4-glfd.server.ntli.net...
> Hi
>
> I've not used DBI before and am having problems getting the hang of
binding.
>
> I have a routine like this:
>
> ============================
> # --- prepare query --- #
>
> if($by eq "thread"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE
'%$display%'
> OR messageid = '$display' ORDER BY article DESC");}
>
> elsif($by eq "poster"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE poster =
'$display'
> ORDER BY thedate DESC");}
>
> elsif($by eq "date"){
>   $sth = $db->prepare("SELECT * FROM thetable
> WHERE thedate LIKE '$display%' ORDER BY thedate DESC");}
>
> # --- execute the query --- #
>
> if(!$sth->execute){
>   print "Failed to get data from thetable";}
>
> else{
>   while(@row = $sth->fetchrow_array){
>     # code to process records
>   }
> }
> ============================
>
> What that does is checks to see what format the data in $display is
going to
> by looking at the $by variable. It then prepares the appropriate
SELECT
> query.
>
> $display will either be the reference of posting that started a thread
in a
> newsgroup, or the poster's name, or the date. The query needs to match
the
> contents of the appropriate column in different ways (ie: some of them
use
> LIKE and wildcards.. this is Jet SQL to an Access database, btw).
>
> The problem is that $display can contain any characters, so after a
previous
> enquiry Benjamin kindly pointed me in the direction of "binding".
>
> So, I've tried substituting $display for a ? and then doing
> "$sth->execute($display)" but it didn't pick up any records (plus when
> retrieving records by thread, it wants 2 bind parameters). I guess I
must be
> using the bind thingies incorrectly, but I've failed to crack it so
far, so
> wondering if anyone can give me a further pointer?
>
> Many thanks
>
> Bigus
>
>
The next  step to find your problem, is to verify that $display does
contain exactly what you think it does.  If so, I have found useful
trick for the "no binding" approach, that  may work for binding as well.

Intentionally make an error in another part of your SQL (e.g. misspell
'OR' as 'AR').  The error message will include the expanded statement.
It is usually not hard to fix the characters that are not exactly what
you expected.

Sorry I can't be more explicit,

Good Luck,
Bill




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

Date: Sat, 12 Apr 2003 16:19:14 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: DBI and binding
Message-Id: <mbudash-DDC399.09191612042003@typhoon.sonic.net>

In article <HiRla.1512$Aq1.8@newsfep4-winn.server.ntli.net>,
 "Bigus" <bigus NO @ SPAM creationfactor .net> wrote:

> "Michael Budash" <mbudash@sonic.net> wrote in message
> news:mbudash-018449.16094711042003@typhoon.sonic.net...
> > In article <k9Hla.210$FA6.4057@newsfep4-glfd.server.ntli.net>,
> >  "Bigus" <bigus NO @ SPAM creationfactor .net> wrote:
> >>
> > > if($by eq "thread"){
> > >   $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE
> '%$display%'
> > > OR messageid = '$display' ORDER BY article DESC");}
> 
> [..]
> 
> > $quoted_display = $db->quote($display);
> >
> > now use $quoted_display in place of $display in your above sql
> > statements.
> 
> Hi.. the problem there is that I'm using wildcards in the criteria and
> $db->quote() places quotes at either end of the string. Eg: when getting
> records by thread, as in the if() condition above, I get the following error
> message:
> 
> Microsoft][ODBC Microsoft Access Driver] Syntax error in query expression
> 'refs LIKE %'b5nbe7.mo.1@hamster.local.invalid'% OR messageid =
> 'b5nbe7.mo.1@hamster.local.invalid''. (SQL-42000)(DBD: st_prepare/SQLPrepare
> err=-1)
> 
> Where I am searching the refs column in the DB I need wildcards either side
> of the messageid, but of course they are outside the quotes that
> $db->quote() applies, hence the syntax error.
> 
> Would placing the wildcards into $display before processing it with
> $db->quote() be the best way or might it try and escape the wildcards?
> 
> Perhaps I should place the wildcards into the $quoted_display with something
> like:
> 
> $quoted_display =~ s/^\'(.*)\'$/\'%$1%\'/;
> 
> .. but I would need a separate $quoted_display for the second condition
> where it looks for a match on messageid and doesn't need wildcards, so it's
> starting to rapidly get messy - is this really the right way to go about it?

well, i really don't think binding (or are you talking about 
placeholders?) is going to work for you, so... yes, i'd go with the 
regex handling (UNtested):

my $quoted_display = $db->quote($display);
my $like_quoted_display;

if ($by eq 'thread'){
  ($like_quoted_display = $quoted_display) =~ s/^'(.+)'$/'%$1%'/;
  $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE 
$like_quoted_display OR messageid = $quoted_display ORDER BY article 
DESC");
}

elsif ($by eq 'poster'){
  $sth = $db->prepare("SELECT * FROM thetable WHERE poster = 
$quoted_display ORDER BY thedate DESC");
}

elsif ($by eq 'date'){
  ($like_quoted_display = $quoted_display) =~ s/(.+)'$/$1%'/;
  $sth = $db->prepare("SELECT * FROM thetable WHERE thedate LIKE 
$like_quoted_display ORDER BY thedate DESC");
}

hth-

-- 
Michael Budash


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

Date: Sat, 12 Apr 2003 14:29:01 +0100
From: James Reeves <arevos@arevol.co.uk>
Subject: Dynamic loading of modules
Message-Id: <vGUla.557$FA6.7801@newsfep4-glfd.server.ntli.net>

So far I have some code that looks something like this:

if ($pagename eq 'journal')
{
        use Journal;
        $page = Journal::output(\%args, \%session);
}
elsif ($pagename eq 'editor')
{
        use Editor;
        $page = Editor::output(\%args, \%session);
}
 .
 .
 .
etc.

Does anyone know if it is possible to access a module with a scalar, so that
I could replace the above with something like:

use $pagename;
$page = $pagename::output(\%args, \%session);

Any help would be greatly appreciated :) - though as far as I can tell, this
isn't possible to do in perl. Except possibly using "eval", but then that
loses the advantage of precompiling the code (this is a mod_perl handler),
or wouldn't this make much difference?

-- 
James Reeves
http://www.arevol.co.uk


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

Date: Sat, 12 Apr 2003 16:28:04 +0200
From: Norbert Schmidt <me@privacy.net>
Subject: Re: Dynamic loading of modules
Message-Id: <d11nf8jm2etr.1ckb7cr0bewvd.dlg@40tude.net>

Hello James,

> use $pagename;
> $page = $pagename::output(\%args, \%session);

try "require" instead of "use".


> though as far as I can tell, this isn't possible to do in perl.

Look again ... ;-)

"use" is evaluated at compile time, "require" at runtime. It won't make 
much difference, since a module is compiled the first time it is required.


Regards, Norbert


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

Date: Sat, 12 Apr 2003 19:30:36 +0200
From: "Dieter D'Hoker" <webmaster@neverseenbefore.com>
Subject: IO::Socket and  IPv6 ?
Message-Id: <b79ig1$chg3r$1@ID-155251.news.dfncis.de>

Could I make my perl programms using IO::Socket compatible with IPv6 in perl
or is tha tnot supported yet ?


--
Dieter D'Hoker
http://dieter.dhoker.com/
news:free.nl.dieter.dhoker & news:alt.nl.fan.dieter.dhoker
Tetrinet SeRVer : TSRV.COM




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

Date: 12 Apr 2003 06:31:23 -0700
From: chacrint@hotmail.com (Chacrint Charinthorn)
Subject: LWP Problem with 500 (Internal Server Error) Can't read entity body
Message-Id: <bfe227db.0304120531.747fc423@posting.google.com>

I tried to post using LWP but I got the following error:

500 (Internal Server Error) Can't read entity body: Connection reset by peer

is it the problem with the problem I tried to post to?

Below is my code:
---------------------------------

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new('Poster/1.0 ');
$ua->agent('Poster/1.0');
BEGIN { $LWP::DebugFile::outpath = './tmp/' }
use LWP::DebugFile ('+');
 .
 .
 .
  $count=1;

  while ($count <= $maxnum) {

    my $req = POST $posturl,
      [
        refno => $refno,
        snum => $snum,
        dservice => $dservice,
        $namediff => $strdiff,
        typemobile => $typemobile
      ];

    $content = $ua->request($req)->as_string;

    foreach (split(/\n/,$content))
    {
      $_ =~ s/\s//g; # To eliminate white spaces
      if ($_ eq 'Status=0') {
        print("Posted to $snum\_$refno -$count- $tmstamp\n");
        $status = $_;
        &write_log_file;
        exit;
      }


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

Date: Sat, 12 Apr 2003 08:13:05 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: LWP Problem with 500 (Internal Server Error) Can't read entity body
Message-Id: <3E981EF1.3040406@indra.com>

perldoc -q 500

--
Ron Reidy
Oracle DBA

Chacrint Charinthorn wrote:
> I tried to post using LWP but I got the following error:
> 
> 500 (Internal Server Error) Can't read entity body: Connection reset by peer
> 
> is it the problem with the problem I tried to post to?
> 
> Below is my code:
> ---------------------------------
> 
> use HTTP::Request::Common qw(POST);
> use LWP::UserAgent;
> $ua = LWP::UserAgent->new('Poster/1.0 ');
> $ua->agent('Poster/1.0');
> BEGIN { $LWP::DebugFile::outpath = './tmp/' }
> use LWP::DebugFile ('+');
> .
> .
> .
>   $count=1;
> 
>   while ($count <= $maxnum) {
> 
>     my $req = POST $posturl,
>       [
>         refno => $refno,
>         snum => $snum,
>         dservice => $dservice,
>         $namediff => $strdiff,
>         typemobile => $typemobile
>       ];
> 
>     $content = $ua->request($req)->as_string;
> 
>     foreach (split(/\n/,$content))
>     {
>       $_ =~ s/\s//g; # To eliminate white spaces
>       if ($_ eq 'Status=0') {
>         print("Posted to $snum\_$refno -$count- $tmstamp\n");
>         $status = $_;
>         &write_log_file;
>         exit;
>       }



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

Date: 12 Apr 2003 09:51:11 -0700
From: molivier@caregroup.harvard.edu (supportgeek)
Subject: match identical lines of file.
Message-Id: <da063e5d.0304120851.59bd11c2@posting.google.com>

ok. i'm stuck on another one. 

using the below code (graciously posted by a member of this group!,
which blew mine away.)
i need to search for an account number and then after the match is
made read down the file, until i find the next match (/^0764/) but I
need the search to end after the first occurnece of a line not
matching /^0764/. I tried using until, but am having no luck. Just
pointing me in the right direction would be great. Thanks in adavance.

Example of file im searching

FOO INSURANCE GROUP
BART SIMPSON
1014560           #Account number
meaningless text
meaningless text
0764    $300            #need to match this
0764    $500            #need to match this
0982    $500            #search needs to stop here!
                        #when first line doesn't match

BAR INSURANCE INC
L.Skywalker
1014534560           
meaningless text
meaningless text
0764    $300            #the below code matches these
0764    $500            #two occurences as well, but
0982    $500            #i need to search to stop as
                        #soon as the next line does not
                        #match ^0764


the code.
------------------------------------------------
use strict;

open (IN, "test.txt") or die $!;

my $acct = "009813945";

my @lines = <IN>;

my $found_acct;

foreach (@lines) {
 unless ($found_acct) {
  if (/$acct/) {
    print $_;
    $found_acct++;
  }
 }
 else {
  if (/^0764/) {
   print $_;
  }
 }
}
----------------------------------------------


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

Date: Sat, 12 Apr 2003 17:40:13 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: match identical lines of file.
Message-Id: <3E984F4E.7050905@rochester.rr.com>

supportgeek wrote:

 ...
> using the below code (graciously posted by a member of this group!,
> which blew mine away.)
> i need to search for an account number and then after the match is
> made read down the file, until i find the next match (/^0764/) but I
> need the search to end after the first occurnece of a line not
> matching /^0764/. I tried using until, but am having no luck. Just
> pointing me in the right direction would be great. Thanks in adavance.
> 
> Example of file im searching
> 
> FOO INSURANCE GROUP
> BART SIMPSON
> 1014560           #Account number
> meaningless text
> meaningless text
> 0764    $300            #need to match this
> 0764    $500            #need to match this
> 0982    $500            #search needs to stop here!
>                         #when first line doesn't match
> 
> BAR INSURANCE INC
> L.Skywalker
> 1014534560           
> meaningless text
> meaningless text
> 0764    $300            #the below code matches these
> 0764    $500            #two occurences as well, but
> 0982    $500            #i need to search to stop as
>                         #soon as the next line does not
>                         #match ^0764
> 
> 
> the code.


You don't really have a Perl problem, just a logic problem.  You need 
another flag to indicate if you have processed a "0764" line, and a test 
to terminate if you have seen a 0764 line and a non-0764 line is 
encountered.  There might be one more possibility:  Can there ever be a 
case in which a given account doesn't have a "0764" line?  If so, you 
need to also terminate your search for a 0764 line when a record 
separator (apparently a blank line in your file??) is found.  But you 
didn't ask about that.  See markup below...


> ------------------------------------------------
> use strict;
> 
> open (IN, "test.txt") or die $!;
> 
> my $acct = "009813945";
> 
> my @lines = <IN>;
> 
> my $found_acct;

my $got0764;


> 
> foreach (@lines) {
>  unless ($found_acct) {
>   if (/$acct/) {
>     print $_;
>     $found_acct++;
>   }
>  }
>  else {
>   if (/^0764/) {
>    print $_;

     $got0764++;


>   }

    else {last if $got0764}


>  }
> }
> ----------------------------------------------
> 

-- 
Bob Walton



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

Date: Sat, 12 Apr 2003 17:45:33 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: match identical lines of file.
Message-Id: <1hYla.21981$4P1.1923412@newsread2.prod.itd.earthlink.net>

"supportgeek" <molivier@caregroup.harvard.edu> wrote in message

> ok. i'm stuck on another one.
>
> using the below code (graciously posted by a member of this group!,
> which blew mine away.)
> i need to search for an account number and then after the match is
> made read down the file, until i find the next match (/^0764/) but I
> need the search to end after the first occurnece of a line not
> matching /^0764/. I tried using until, but am having no luck. Just
> pointing me in the right direction would be great. Thanks in adavance.
>
> Example of file im searching
>
> FOO INSURANCE GROUP
> BART SIMPSON
> 1014560           #Account number
> meaningless text
> meaningless text
> 0764    $300            #need to match this
> 0764    $500            #need to match this
> 0982    $500            #search needs to stop here!
>                         #when first line doesn't match
>
> BAR INSURANCE INC
> L.Skywalker
> 1014534560
> meaningless text
> meaningless text
> 0764    $300            #the below code matches these
> 0764    $500            #two occurences as well, but
> 0982    $500            #i need to search to stop as
>                         #soon as the next line does not
>                         #match ^0764

The question isn't so much the code as it is knowing your
data.  Please post some exact data.  For example,
Is each set of data followed by a blank (\n) line?
Is there always an uppercase "company" line before each
set?  Is the account number alway on a line by itself
and how many numbers is it?  Is it fixed or variable?
If it is variable, what are the min/max?  Is an account
number always numbers?

I parse phone books with perl and if you know the data
you are parsing, you can do wonders.

A hint in the right direction would be once you know
you are processing a different customer, stop.

HTH,

Jodyman




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

Date: Sat, 12 Apr 2003 21:03:09 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Newline problem
Message-Id: <b79bjr$18b$1@newsreader.mailgate.org>

Good Morning,

I have made a perl script which reads email addresses and Text Message to be
sent using Net::SMTP.

The input file is a simple text file with "NAME<TAB>Message\n" format...i.e
Name and Messages are tab seperated and each record is in a newline.
My code does $smtp->datasend("$message") but I can't figure out a way to put
newlines in the email.

For eg, consider the message being as:
Hello ABC,\n Nice to Meet you.\nRegards,\nXYZ.

I want this to appear in email as :
Hello ABC,
Nice to Meet you.
Regards,
XYZ.

But I can't get these \n converted to newlines.
Where is the problem, scanning the data from text file or while sending the
email data?
How can I solve it?

TIA,
Kasp
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall






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

Date: Sat, 12 Apr 2003 16:02:44 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Newline problem
Message-Id: <mbudash-DB5426.09024612042003@typhoon.sonic.net>

In article <b79bjr$18b$1@newsreader.mailgate.org>,
 "Kasp" <kasp@epatra.com> wrote:

> Good Morning,
> 
> I have made a perl script which reads email addresses and Text Message to be
> sent using Net::SMTP.
> 
> The input file is a simple text file with "NAME<TAB>Message\n" format...i.e
> Name and Messages are tab seperated and each record is in a newline.
> My code does $smtp->datasend("$message") but I can't figure out a way to put
> newlines in the email.

that oughta do it... let's see the real code...

-- 
Michael Budash


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

Date: Sat, 12 Apr 2003 22:43:30 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Newline problem
Message-Id: <b79hgi$98i$1@newsreader.mailgate.org>

Here is the test input file called test.txt

abc 123\n456\n789
123 Make\nThe\n Newlines\nwork!!

Here is the code snippet:

open(IN_FILE,"test.txt") || die "Failed to open file .$!";
while(defined( $lineRead = <IN_FILE>) ) #Read one line at a time
{
chomp($lineRead);

#split line read based on TABS
($NAME, $MESSAGE) = split(/\t/, $lineRead);
sendMail( $MESSAGE);
print "Mail sent to $NAME";

}
close(IN_FILE);


sub sendMail(){

my ($message) = @_;

use Net::SMTP;
$smtp = Net::SMTP->new(mailServer);
$smtp->mail('kasp@epatra.com');
$smtp->to('you@mail.com');
$smtp->data();
$smtp->datasend("Subject: Hi\n");
$smtp->datasend("To: you\@mail.com\n");
$smtp->datasend("\n");

$smtp->datasend("$message");

$smtp->dataend();
$smtp->quit;
}


--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall










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

Date: 12 Apr 2003 14:41:54 GMT
From: Michael Lapsley <spamtrap@lapsley.ukshells.co.uk>
Subject: problem with Term::ReadKey
Message-Id: <slrnb9g9dh.2bv.spamtrap@rift.ukshells.co.uk>

Hi all,

A program that I have that is dependent on Term::ReadKey has
mysteriously stopped working:  user input does not have any
effect at all. (RH8.0, perl 5.8 see output of -V below)

I copied the following from the Term::ReadKey manpage and, sure enough,
it does not work either.  There is no response from the keyboard,
I have to kill it with -9, and when it dies there are the keystrokes
sitting at the command prompt.

I am not sure how I can gather any more info.  Presumably it is a bug
either in Term::ReadKey or in perl 5.8.  It still works on my old machine
running perl 5.6.1 (RH7.?)

The affected machine is RH8.0   The last perl woes I had I eventually
traced to unicode, but I cannot see a link here.  Any ideas?

Thanks,

Michael

#!/usr/bin/perl
use strict;
use Term::ReadKey;
my $key;
ReadMode 4; # Turn off controls keys
while (not defined ($key = ReadKey(-1))) {
       # No key yet
}
print "Get key $key\n";
ReadMode 0; # Reset tty mode before exiting

-----

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18-11smp, archname=i386-linux-thread-multi
    uname='linux daffy.perf.redhat.com 2.4.18-11smp #1 smp thu aug 15
    06:41:59 edt 2002 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686
    -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red
    Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux
    -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads
    -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun
    -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm
    -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly
    -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
    usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
    -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -march=i386 -mcpu=i686',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
    -I/usr/include/gdbm'
    ccversion='', gccversion='3.2 20020822 (Red Hat Linux Rawhide 3.2-5)',
    gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.92.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.2.92'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic
    -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
  PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Sep  1 2002 23:56:49
  @INC:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .


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

Date: 12 Apr 2003 06:10:23 -0700
From: molivier@caregroup.harvard.edu (supportgeek)
Subject: Re: Search for text than search again based on results.
Message-Id: <da063e5d.0304120510.28969aa8@posting.google.com>

many thanks guys.


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

Date: 12 Apr 2003 06:28:19 -0700
From: molivier@caregroup.harvard.edu (supportgeek)
Subject: Re: Search for text than search again based on results.
Message-Id: <da063e5d.0304120528.25cd2d25@posting.google.com>

Hey this code works great.

If you get a chance. would you mind explaining how the "unless
($found_acct)" works. i've looked it up in a few books, but I havent
seen it used like this.

also do you think i am better off not reading the entire file in to
memory.
the files that I am reading are extremely large and there are about 30
of them.

thanks again.

> 
> since it looks like you _want_ to read the whole file into memory, i'll 
> continue with that method:
> 
> #!usr/bin/perl
> 
> use strict;
> 
> open (IN, "test.txt") or die $!;
> 
> my @lines = <IN>;
> 
> my $found_acct;
> 
> foreach (@lines) {
>  unless ($found_acct) {
>   if (/$acct/) {
>     print $_;
>     $found_acct++;
>   }
>  }
>  else {
>   if (/^0764/) {
>    print $_;
>   }
>  }
> }
> 
> hth-


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

Date: Sat, 12 Apr 2003 16:00:01 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Search for text than search again based on results.
Message-Id: <mbudash-1BF111.09000212042003@typhoon.sonic.net>

In article <da063e5d.0304120528.25cd2d25@posting.google.com>,
 molivier@caregroup.harvard.edu (supportgeek) wrote:

> > 
> > since it looks like you _want_ to read the whole file into memory, i'll 
> > continue with that method:
> > 
> > #!usr/bin/perl
> > 
> > use strict;
> > 
> > open (IN, "test.txt") or die $!;
> > 
> > my @lines = <IN>;
> > 
> > my $found_acct;
> > 
> > foreach (@lines) {
> >  unless ($found_acct) {
> >   if (/$acct/) {
> >     print $_;
> >     $found_acct++;
> >   }
> >  }
> >  else {
> >   if (/^0764/) {
> >    print $_;
> >   }
> >  }
> > }
> > 
> > hth-
>
> Hey this code works great.

good

> If you get a chance. would you mind explaining how the "unless
> ($found_acct)" works. i've looked it up in a few books, but I havent
> seen it used like this.

perldoc perlsyn

it works as in english:

unless (this condition is true) {
 do this
}

the condition in this case is a true value in $found_acct, which will 
only be the case if the var's been incremented a few lines down.

> also do you think i am better off not reading the entire file in to 
> memory. the files that I am reading are extremely large and there are 
> about 30 of them.

why read it in if you're not going to use all of it? try this:


open (IN, "test.txt") or die $!;

my $found_acct;

while (<IN>) {
 unless ($found_acct) {
  if (/$acct/) {
    print $_;
    $found_acct++;
  }
 }
 else {
  if (/^0764/) {
   print $_;
   last;
  }
 }
}

close (IN);

hth-

-- 
Michael Budash


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

Date: Sat, 12 Apr 2003 16:04:49 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Search for text than search again based on results.
Message-Id: <BOWla.49252$Xd1.16455068@news4.srv.hcvlny.cv.net>


"supportgeek" <molivier@caregroup.harvard.edu> wrote in message
news:da063e5d.0304111734.1f6d3b35@posting.google.com...
> Greetings.
>
> I would greatly appreciate it if someone could point me in the right
> direction on this one:
>
> What I need to accomplish: I search for an account and once I find it
> I need to search down in the file until I find the first occurence of
> a line beginning in 0764
>
> Here's what I'm working with.
>
> #!usr/bin/perl
>
> open (IN, "test.txt") or die $!;
>
> @lines = <IN>;
>
> foreach $_(@lines) {
>   if ($_ =~ /$acct/) {
>   print $_;
>
>   #this is where i need something in the way of search down file until
>   #$_ = /^0764/
>
>   }
> }
>
> any help on this would be great.

Loops are not necessary at all if you are willing to read the entire
file into a single string.

use strict;
use warnings;
local $/ = '';
my $act_pat = 'MyAccount';
my $whole_file = <DATA>;
(my $desired_line) = $whole_file =~ /$act_pat.*\n(0764[^\n]*)\n/s;
print $desired_line;
__END__
Bla,bla,
bla
bla, MyAccount
Bla
0764 This is the data you want
blah,blah
BBBB

Enjoy,
Bill




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

Date: 12 Apr 2003 08:29:19 -0700
From: bruno@Skorepa.com (Bruno Skorepa)
Subject: split question
Message-Id: <59f4f754.0304120729.55bcc683@posting.google.com>

split question:

Excel spreadsheets can be exported to textfiles, where columns are
seperated by commas:
for example:

364,Tools,Import Ärzte aus Kammerdatei (VPN)

I split this line:

($bugid,$topic,$bug) = split /,/, $_;

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

So far so good.
If there is a comma in one of the columns, Excel puts the data within
"..."
for example:

370,SKF,4/3/2003,Warteliste,"termin editieren, pat wählen",,,,,,

If there is a " within the data, Excel escapes that by a second one:
for example:

377,Dorfinger,4/15/2003,WinMed,"Der Cursor bleibt beim
Fensterverschieben ""kleben"", so daß man oft ungewollt das Fenster
verschiebt",,,,,,

can this be done with one split command?

thanks for any hints,
Bruno.


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

Date: Sat, 12 Apr 2003 16:09:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: split question
Message-Id: <VSWla.1215$ok3.352@nwrddc03.gnilink.net>

Bruno Skorepa wrote:
[Attempt to use split and REs to separate fields in a CSV]
> can this be done with one split command?

You may be better off using Text::CSV instead of trying to reinvent the
wheel.

jue




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

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


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