[22666] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4887 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 24 14:07:49 2003

Date: Thu, 24 Apr 2003 11:05:09 -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           Thu, 24 Apr 2003     Volume: 10 Number: 4887

Today's topics:
    Re: Advice: Perl + XML - Native Perl module? <abigail@abigail.nl>
    Re: Advice: Perl + XML - Native Perl module? (MegaZone)
    Re: Advice: Perl + XML - Native Perl module? (MegaZone)
    Re: cant connect to remote database <simon.andrews@bbsrc.ac.uk>
    Re: cant connect to remote database <rereidy@indra.com>
    Re: changing the date <member17678@dbforums.com>
    Re: Distribute a perl script (dan baker)
    Re: Distribute a perl script <ethan@draupnir.gso.saic.com>
    Re: looking for graphing program <abigail@abigail.nl>
    Re: looking for graphing program <bart.lateur@pandora.be>
    Re: looking for graphing program <abigail@abigail.nl>
    Re: Matching multiple lines <ccsc3618@bigpond.net.au>
    Re: parsing perl code (audit, summarize, trace) <w.koenig@acm.org>
    Re: reg expr prl newbie <barryk2@SPAM-KILLER.mts.net>
    Re: Regex greediness question <noreply@gunnar.cc>
    Re: Regex greediness question <noreply@gunnar.cc>
    Re: Regex greediness question <mjcarman@mchsi.com>
    Re: Still Stumped <delautenschl@[nospam]wisc.edu>
    Re: Still Stumped (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 24 Apr 2003 13:06:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Advice: Perl + XML - Native Perl module?
Message-Id: <slrnbafo9v.inc.abigail@alexandra.abigail.nl>

MegaZone (usenet@megazone.org) wrote on MMMDXXIII September MCMXCIII in
<URL:news:megazone.1051154309@sidehack.sat.gweep.net>:
**  
**  I was looking at lib::XML, but that's an XS wrapper to C - performance
**  isn't an overriding concern, but portability is.  If possible, I'd
**  like to use an XML module that is native Perl.  (It looks like
**  XML::Twig is, right?)  Ideally the code will end up portable across
**  UNIX/Linux and Windows platforms.


Why would a module written in C not be portable? It might not
compile on all your intended platforms, but did you try? 

Remember that perl itself isn't written in Perl, but in C. Yet
it is cross-platform.



Abigail
-- 
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
           ${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'


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

Date: 24 Apr 2003 15:57:23 GMT
From: usenet@megazone.org (MegaZone)
Subject: Re: Advice: Perl + XML - Native Perl module?
Message-Id: <megazone.1051199843@sidehack.sat.gweep.net>

abigail@abigail.nl shaped the electrons to say:
>Why would a module written in C not be portable? It might not
>compile on all your intended platforms, but did you try? 

This is code sent out to customers - we don't really know *what* the
platforms will be in the end.  Just 'Perl' - and from some of the
customers I've worked with so far, getting them to compile things
would be torture.  We do already have a cryptography object written
in C++ that needs to be compiled on UNIX platforms (there is a COM
object for Windows) and I've had to deal with customers compiling that
already.

I haven't ruled out a C-based module, I just wanted to make sure I
wasn't missing something obvious.  A Perl-only solution would just
remove a potential hiccup.  And I was just interested in opinions on
the different options.

-MZ, CISSP #3762, RHCE #806199299900541
-- 
<URL:mailto:megazone@megazone.org> Gweep, Discordian, Author, Engineer, me..
"A little nonsense now and then, is relished by the wisest men" 508-755-4098
<URL:http://www.megazone.org/>  <URL:http://www.eyrie-productions.com/> Eris


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

Date: 24 Apr 2003 16:14:12 GMT
From: usenet@megazone.org (MegaZone)
Subject: Re: Advice: Perl + XML - Native Perl module?
Message-Id: <megazone.1051200851@sidehack.sat.gweep.net>

merlyn@stonehenge.com (Randal L. Schwartz) shaped the electrons to say:
>Interesting... "Pure Perl" "XML Parser"'s second hit in Google
>(right now) is XML::SAX::PurePerl.  Perhaps you can see if that
>fits your needs.  It does claim that it is <b>slow</b>. :)

Well, what you search on is certainly important. :-)  It never
occurred to me to use "Pure Perl" - I was doing things like 'native
perl', 'perl only', etc.

I'll check that out.

And maybe someday I'll have some time to work on the TiVo Server. :-)

-MZ, CISSP #3762, RHCE #806199299900541
-- 
<URL:mailto:megazone@megazone.org> Gweep, Discordian, Author, Engineer, me..
"A little nonsense now and then, is relished by the wisest men" 508-755-4098
<URL:http://www.megazone.org/>  <URL:http://www.eyrie-productions.com/> Eris


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

Date: Thu, 24 Apr 2003 14:12:40 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: cant connect to remote database
Message-Id: <3EA7E2C8.3080309@bbsrc.ac.uk>



a_wim wrote:
> Ron Reidy <rereidy@indra.com> wrote in message news:<3EA7439A.40208@indra.com>...
> 
>>What does "i can't connect to the remote database ..." mean?  What is 
>>your Oracle error message?
>>
>>--
>>Ron Reidy
>>Oracle DBA
>>
>>a_wim wrote:
>>
>>>hi everybody,
>>>im in big trouble, i hope there is anybody who can help me!
>>>i want to connect to a database which is installd on hpux system
> 
> hi ron,
> here is the code and the error-message.........
 >
>
> #!/usr/local/bin/perl
> 
> use DBI;
> use DBI::DBD;
> 
> $dbh = DBI->connect('DBI:driver:database', 'xxx', 'xxx',
>             { RaiseError => 1, AutoCommit => 1});


OK this is where your problems start.  Your connect statement looks like 
you've taken it straight from a generic example, without altering it to 
what you actually want to do.  Where it says DBI:driver:database you 
need to replace 'driver' and 'database' with the actual driver you want 
to use and database you want to connect to.  You said you installed the
"DBD-modul", but you didn't say which one.  There is a different DBD 
module for each database type and you need to make sure you installed 
the right one (eg DBD::Oracle, DBD::Informix etc.).  You then specify 
this DBD in your DBI connection string.

Also you should replace 'database' with the name of the actual database 
you want to connect to.  There are a couple of ways of specifying this 
and you should read the documentation with your DBD module to see what 
the correct one is for your database.  If you're using Oracle then read 
"perldoc DBD::Oracle" where there is a whole section on specifying 
connection strings.

I assume that you realise that the 'xxx','xxx' bit of the connect string 
should be filled with the username and password you use to connect to 
the database.

You should end up with something which looks a bit like this though:


$dbh = DBI->connect('dbi:Oracle:host=your.database.server;sid=ORCL',
                     'username',
                     'password',
                     { RaiseError => 1, AutoCommit => 1});

unless ($dbh) {
	die "Can't connect to database: $DBD::errstr";
}	


OK, let's assume you've now connected...

> $dbh->do($SQL);


> $sth = $dbh->prepare($SQL);
> $sth->execute();

These are two ways of doing the same thing.  The $dbh->do notation is 
good for a single query which you'll only run once, and in which you 
don't need to worry about quoting unusual characters.

The prepare / execute syntax is better for a query which will be run 
multiple times, possibly with different parameters passed to it.  This 
will also take care of quoting characters with special meaning for you. 
  See the DBI documentation for all of this.

In either case you need to actually put some SQL into $SQL so the 
database knows what you want to do.

$sql = 'select * from table where some_column_name=? limit 10';

$sth = $dbh -> prepare($SQL);
$sth -> execute('some value') or die "Can't execute statement: ".$dbh -> 
errstr();

In this case the ? in the SQL is a placeholder which is replaced by a 
value you supply in the execute statement.  You can therefore prepare a 
query once, and execute it many times, with different values passed each 
time.

> while (@row = $sth->fetchrow_array) {

This is OK, but you don't actually do anything with the data you fetch. 
  You could at least print it with something like:

	print join("\t",@row),"\n";

> }
> $sth->finish();
> $dbh->disconnect();

[snip errors]


> Available drivers: ExampleP, Oracle, Proxy.

So it looks like you have already installed the Oracle driver, so this 
is probably the one you wanted to use?

I hope this helps to get you started.

	TTFN

	Simon.



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

Date: Thu, 24 Apr 2003 07:46:46 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: cant connect to remote database
Message-Id: <3EA7EAC6.1050201@indra.com>

 From your original post, I am assuming you are using Oracle.  Did you:

1.  Install the Oracle client (minimum requirement) on the server you 
are running this script from?
2.  Confirugre Net8 (tnsnames or LDAP, etc.) and test the connectivity 
with SQL*Plus?
3.  Install DBD::Oracle from CPAN?
4.  Read the DBI and DBD::Oracle docs?

See below ...

--
Ron Reidy
Oracle DBA

a_wim wrote:
> Ron Reidy <rereidy@indra.com> wrote in message news:<3EA7439A.40208@indra.com>...
> 
>>What does "i can't connect to the remote database ..." mean?  What is 
>>your Oracle error message?
>>
>>--
>>Ron Reidy
>>Oracle DBA
>>
>>a_wim wrote:
>>
>>>hi everybody,
>>>im in big trouble, i hope there is anybody who can help me!
>>>i want to connect to a database which is installd on hpux system and i
>>>want to
>>>connect from a sun to this database. on both machins, perl is
>>>installed and the oci driver although. on the sun machine i had
>>>installed the DBI-modul and DBD-modul
>>>the test-skript which were included in the DBD-module-direction works
>>>fine.
>>>now my problem:
>>>i cant connect to the remote database on the hpux, with my own perl
>>>skript !!!!!
>>>what can i do? or which modul i need more? 
>>>
>>>thanx for help
>>>bye
>>
> 
> hi ron,
> here is the code and the error-message.........
> the message dbd::driver not fully installed, tells me nothing, because
> there is no module which i can take to install the driver.
> thanx for your help!!!!
> 
> 
> #!/usr/local/bin/perl
> 
> use DBI;
> use DBI::DBD;
> 
> $dbh = DBI->connect('DBI:driver:database', 'xxx', 'xxx',
What is                    ^^^^^^  ^^^^^^^?  If using Oracle, the value 
of driver should (must) be 'Oracle'.  The value for database should be 
the name of the Oracle instance you want to connect to (service name or 
ORACLE_SID).

>             { RaiseError => 1, AutoCommit => 1});
> $dbh->do($SQL);
> $sth = $dbh->prepare($SQL);
> $sth->execute();
> while (@row = $sth->fetchrow_array) {
>     # ...
> }
> $sth->finish();
> $dbh->disconnect();
> 
> ~
> ~
> ~
> ~
> ~
> "DBI.pl" 16 lines, 309 characters
> awimmer.NOSID.mpsun01> perl DBI.pl
> install_driver(driver) failed: Can't locate DBD/driver.pm in @INC
> (@INC contains: /usr/local/lib/perl5/5.8.0/sun4-solaris
> /usr/local/lib/perl5/5.8.0
> /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris
> /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl .)
> at (eval 1) line 3.
> Perhaps the DBD::driver perl module hasn't been fully installed,
> or perhaps the capitalisation of 'driver' isn't right.
> Available drivers: ExampleP, Oracle, Proxy.



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

Date: Thu, 24 Apr 2003 16:09:55 +0000
From: Mario542 <member17678@dbforums.com>
Subject: Re: changing the date
Message-Id: <2802706.1051200595@dbforums.com>


Steffen,

when someone enters a date into the web for it look like- 4.14.03. How
do I fromat this so it can be changed to the following date- 4.15.03??

--
Posted via http://dbforums.com


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

Date: 24 Apr 2003 07:46:06 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: Distribute a perl script
Message-Id: <13685ef8.0304240646.308ac8c3@posting.google.com>

google@ppatrice.ovh.org (Patrice) wrote in message news:<da445f9c.0304231821.700700c1@posting.google.com>...
> I have done a perl script as a project for univeristy. I am now
> looking for a way to distribute it to my examiners so they can easily
> test it. --------------

or you could build a little web-based test harness/front end interface
and install it in a website they can get to. Could also have links
that would show the source in addition to execution....

d


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

Date: 24 Apr 2003 10:32:55 -0700
From: Ethan Brown <ethan@draupnir.gso.saic.com>
Subject: Re: Distribute a perl script
Message-Id: <vrist3by2g.fsf@draupnir.gso.saic.com>

>>>>> "Dan" == dan baker <botfood@yahoo.com> writes:

    Dan> google@ppatrice.ovh.org (Patrice) wrote in message news:<da445f9c.0304231821.700700c1@posting.google.com>...
    >> I have done a perl script as a project for univeristy. I am now
    >> looking for a way to distribute it to my examiners so they can easily
    >> test it. --------------

    Dan> or you could build a little web-based test harness/front end interface
    Dan> and install it in a website they can get to. Could also have links
    Dan> that would show the source in addition to execution....

    Dan> d

I was also thinking something along these lines.  Another "long way around" 
solution would be to customize Knoppix (see
http://www.knopper.net/knoppix/index-en.html) and then just distribute
Linux along with the application. :-)  Knoppix is pretty cool.  Run
linux from a computer's CDROM without touching the hard disk.

--Ethan Brown
--Keyboards: "The Fabulous Pelicans" (www.pelicans.com)
--In a band?  Use http://www.WheresTheGig.com for free.



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

Date: 24 Apr 2003 13:18:56 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: looking for graphing program
Message-Id: <slrnbafp20.inc.abigail@alexandra.abigail.nl>

Chris (chris_12003@yahoo.com) wrote on MMMDXXIII September MCMXCIII in
<URL:news:vaekga867vgj9d@corp.supernews.com>:
()  Does anyone know of any graphing scripts that I can use that'll take the
()  input from a text file and display a graph to the user.  The graph can
()  either update automatically or through a crontab once a day.  I'm trying to
()  create a bar chart with 2 values to plot and maybe 3 if thats possible.


I do the majority of my plotting with the help of the gnuplot program.
No Perl module needed, just open a pipe to the program.



Abigail
-- 
print 74.117.115.116.32, 97.110.111.116.104.101.114.32,
      80.101.114.108.32, 72.97.99.107.101.114.10;


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

Date: Thu, 24 Apr 2003 15:36:09 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: looking for graphing program
Message-Id: <bv0gavkai4pf51fraqjtk7nvarbg2kv63u@4ax.com>

Chris wrote:

>Does anyone know of any graphing scripts that I can use that'll take the
>input from a text file and display a graph to the user.  The graph can
>either update automatically or through a crontab once a day.  I'm trying to
>create a bar chart with 2 values to plot and maybe 3 if thats possible.

Graphing script, no. But there are a few graphing modules on CPAN which
make writing such a script easy, like GD::Graph

	<http://search.cpan.org/author/MVERB/GDGraph-1.39/Graph.pm>

-- 
	Bart.


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

Date: 24 Apr 2003 16:48:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: looking for graphing program
Message-Id: <slrnbag5bk.jac.abigail@alexandra.abigail.nl>

Chris (chris_12003@yahoo.com) wrote on MMMDXXIII September MCMXCIII in
<URL:news:vaekga867vgj9d@corp.supernews.com>:
[]  Does anyone know of any graphing scripts that I can use that'll take the
[]  input from a text file and display a graph to the user.  The graph can
[]  either update automatically or through a crontab once a day.  I'm trying to
[]  create a bar chart with 2 values to plot and maybe 3 if thats possible.


Below is an example of a "script" that creates graphs. The
script creates the graphs found on <http://www.abigail.nl/Viking/>.


Abigail


#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;

sub my_log;
sub team_plot;
sub people_plot;

my $host      = "stats.distributed.net/";
my $proj      =  8;      # RC5-72.
my $team      =  13165;  # VikingMUD.
my $dir       = "/home/abigail/WWW/Viking";
my $data      = "$dir/viking.dat";
my $outfile   = "$dir/viking.png";
my $outpeople = "$dir/people.png";
my $url       = "http://$host/team/tmsummary.php?project_id=$proj&team=$team";
my $url2      = "http://$host/team/tmember.php?project_id=$proj&team=$team";

my $keys_per_block = 4294967296;

my $text = get $url or die "Failed to get $url\n";

my ($date1) = $text =~ /Data shown reflects all blocks received as of (\S+)/;
my ($keys)  = $text =~
       m!<td[^>]*><font[^>]*>Keys:</font></td> \s+
         <td[^>]*><font[^>]*>([\d,]+)</font>!x;

die "Failed to parse text\n" unless defined $date1 && defined $keys;

my %MON = qw /Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06
              Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12/;


$keys =~ s/,//g;
$keys /= $keys_per_block;
my ($d, $m, $y) = split /-/ => $date1;
my $date = sprintf "%4d-%02d-%02d" => $y, $MON {$m}, $d;

team_plot $data if my_log $data, $date, $keys;

#
# Parsing of people's individual contribution.
#

$text = get $url2 or die "Failed to get $url2: $!\n";

my ($date2) = $text =~ /Data shown reflects all blocks received as of (\S+)/;

die "Date mismatch. Team page says '$date1', member page says '$date2'.\n"
     unless $date1 eq $date2;

my %ids;
my $result   = 0;
while ($text =~ m {
     <a \s+ href="/participant/psummary.php[?]project_id=$proj&id=(\d+)"> \s+
     <font \s+ color="\#cc0000">([^<]+)</font> \s+ </a> \s+ </td> \s+  # Name.
     <td>(?:[^<]+|<(?!td))*
     <td \s+ align="right"> [^<]+ </td> \s+  # Start date.
     <td \s+ align="right">([^<]+)</td> \s+  # End date.
     <td \s+ align="right"> [^<]+ </td> \s+  # Yesterday.
     <td \s+ align="right"> [^<]+ </td> \s+  # Yesterday percentage.
     <td \s+ align="right">([^<]+)</td> \s+  # Total.
     <td \s+ align="right"> [^<]+ </td> \s+  # Total percentage.
     }xg) {
    my ($id, $name, $end_date, $total) = ($1, $2, $3, $4);

    $ids {$id} = $name;
    $total =~ s/,//g;

    my ($d, $m, $y) = split /-/ => $end_date;
    my $date = sprintf "%4d-%02d-%02d" => $y, $MON {$m}, $d;

    my $file = "$dir/person.$id.dat";
    $result += my_log $file, $date, $total;
}

people_plot \%ids if $result;


exit;



sub my_log {
    my ($file, $date, $amount) = @_;

    my $result = 0;
    open my $fh => "+<", $file or die "Failed to open $file: $!\n";
    my $last_date = "";
    while (<$fh>) {
        ($last_date) = split /:\s+/;
    }
    unless ($last_date eq $date) {
        printf $fh "%s:  %d\n" => $date, $amount;
        $result = 1;
    }
    close $fh or die "Failed to close $file: $!\n";

    $result;
}

sub team_plot {
    my $data = shift;

    open my $plot => "| gnuplot" or die "Failed to open pipe: $!\n";

    print $plot <<"--";

    set  terminal png color
    set  out     "$outfile"
    set  xdata    time
    set  timefmt "%Y-%m-%d:"
    set  key      left top Left reverse samplen 2 title "Legend" box

    set  grid     xtics ytics
    set  ytics    nomirror
    set  xtics    nomirror

    set  ylabel  "Blocks"

    plot "$data"  using 1:2 smooth unique title "Viking RC5-72 stats"
--
    close $plot or die "Failed to close pipe: $!\n";
    chmod 0644 => $outfile or die "Failed to chmod $outfile: $!\n";
}



sub people_plot {
    my $ids = shift;

    open my $plot => "| gnuplot" or die "Failed to open pipe: $!\n";

    my @plots;
    foreach my $id (sort {$a <=> $b} keys %$ids) {
        my $file = "$dir/person.$id.dat";
        my $line = qq {"$file" using 1:2 smooth unique title "$ids->{$id}"};
        push @plots => $line;
    }
    my $plots = join ",\\\n     " => @plots;

    print $plot <<"--";

    set  terminal png color
    set  out     "$outpeople"
    set  xdata    time
    set  timefmt "%Y-%m-%d:"
    set  key      left top Left reverse samplen 2 title "Legend" box

    set  grid     xtics ytics
    set  ytics    nomirror
    set  xtics    nomirror

    set  ylabel  "Blocks"
    plot $plots
--
    close $plot or die "Failed to close pipe: $!\n";
    chmod 0644 => $outpeople or die "Failed to chmod $outpeople: $!\n";
}

__END__
-- 
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];


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

Date: Thu, 24 Apr 2003 13:48:40 GMT
From: "rjh" <ccsc3618@bigpond.net.au>
Subject: Re: Matching multiple lines
Message-Id: <YWRpa.9330$8K2.90541@news-server.bigpond.net.au>

Once i changed the record separators i could print $_ if a match was found.

#!/usr/bin/perl -w

use strict;
use Getopt::Std;

my $separator1 = "-----";
my $separator2 = "-------";

if (exists ($opts{G}) ) {
        $line = $opts{G};
        &G;
        exit;

sub G
{
        &OpenFile("-d");
        foreach $filename (readdir(DIRHANDLE)){
            if(-d $filename) {;next;}
            local $/ = "$separator2";
            &OpenFile("-g", $filename);
            while (<FILEHANDLE>) {
                if(/$line/){print "$_\n";}
            }close FILEHANDLE;
        }
        closedir FILEHANDLE;

---->>>>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbad189.t97.tadmc@magna.augustmail.com...
> rjh <ccsc3618@bigpond.net.au> wrote:
>
>
> > Setting $/ to "----------------" works for matching multiple lines, but
how
> > can i match the timestamp above the ---------------.
> > Is there a special var for that ? Does setting $/ to "------------" mean
> > that the timestamp will be missed altogether.
>
>
> No, it means that you will read *two* physical records for
> each logical record. That is, 1st read gets the timestamp,
> 2nd read gets the data.
>
> This is because you've used the same delimiter for both parts. If you
> control the format of the data file, change the "interior" delimiter
> to something else if you want one-read-per-record. Something like:
>
>    2003/12/02 hh:mm --
>    -----
>    this is a piece
>    of multi line
>    text
>    ---------------------
>
>
> >     $timestamp = m/\d{4,}.*/;   # etc etc
>
>
> That accomplishes nothing. You should never have a "bare" m// operator
> like that.
>
> The only useful info you get from a m// is the true (match succeeded)
> or false (match failed) that it returns, so the m// should always
> be in a condition that tests for the success/failure.
>
> Also, that could match the wrong thing with data like:
>
>    2003/12/02 hh:mm --
>    ---------------------
>    the house
>    costs $50000
>    ---------------------
>
> since the "5000" in the 2nd record will match that pattern.
>
>
> > Any thought,
>
> -------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> local $/ = "---------------------\n";
> my $timestamp;
> while ( <DATA> ) {
>    if ( m#^(\d{4}/\d\d/\d\d)# ) {  # timestamp record
>       $timestamp = $1;
>    }
>    else {                          # data record
>       print "$timestamp, $_\n";
>    }
> }
>
>
>
> __DATA__
> 2003/12/02 hh:mm --
> ---------------------
> this is a piece
> of multi line
> text
> ---------------------
> 2003/12/01 hh:mm --
> ---------------------
> this is a single line of text
> ---------------------
> 2003/12/01 hh:mm --
> ---------------------
> this is another multiple
> line of text
> where i just write stuff
> ---------------------
> -------------------------------------------
>
>
> > Recomendations most welcome.
>
>
> Please do not top-post again.
>
>
> [snip TOFU]
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: Thu, 24 Apr 2003 15:07:51 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: parsing perl code (audit, summarize, trace)
Message-Id: <3EA7E1A7.3050808@acm.org>

Eric Wilhelm wrote:
> Is there a module which allows you to parse perl code?
> 
> For example, I would like to write a program which prints all of the
> variables from a list of perl sources (accounting for @array and
> $array[0] only once).
> 
> Suggestions?
> 
> Thanks,
> Eric

start with:

$ perl -MO=Xref some_script.pl

then read 'perldoc O' and 'perldoc B::Xref'.

Winfried Koenig





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

Date: Thu, 24 Apr 2003 08:11:25 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: reg expr prl newbie
Message-Id: <MPG.19119e7599a32cfc9897ad@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <74a4a6df.0304230854.26d04bad@posting.google.com>, James 
Peterson (sonique55105@yahoo.com) says...
> i want to extract the title from a number of html pages and i was told
> i could do this in perl but i am having troubles with it. Basically i
> want to grab whatever lies between <title> and </title> but i always
> seem to get errors when i have </title> in my regular expression
> because (i suppose) perl assumes that / denotes the end of the match.
> Can anyone point me to a correct reg expr that will grab PAGE TITLE
> from <title>PAGE TITLE</title>?
> 
> Thanks!
> 


$buffer = "<title>PAGE TITLE</title>";
if ( $buffer =~ m/<title>(.*?)<\/title>/ ) {
    $title = $1;
    print "Found a title : $title\n";
}

-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: Thu, 24 Apr 2003 16:07:29 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex greediness question
Message-Id: <b88raf$7ei6u$1@ID-184292.news.dfncis.de>

Tman wrote:
> C:\Temp>perl -de 1
> .....
>   DB<1> p "aaaaaabaaaaa" =~ /a(.*?b.*?)a/
> aaaaab
> 
> I was hoping to capture only "b" in the capture group.  By making
> both of the quantifiers non-greedy, it seems that the man page for
> perlre says that they will match the "minimum number of times
> possible".  Well, this regex matches fine if both of the
> quantifiers match _zero_ items.  But the leftmost one wants to
> match more than the minimum.

perlre says also: "given a particular starting location". It starts
with the *first* a it finds, and tries to match from that.

> Trvial example, yes, but it is reduced from a real-world problem.
> (I am trying to match the <TABLE>..... </TABLE> element in a page
> that contains a certain string, and only match that single table).

If that's what you intend to do, I don't think that your example
string illustrates it. I mean, hopefully your HTML distinguishes
between <TABLE> and </TABLE>...

How about this:

     $html =~ s[(<table>.*?</table>)][
         my $table = $1;
         if ($table =~ /$string/) {
             # do something
         } else {
             $table;
         }
     ]egi;

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 24 Apr 2003 16:22:43 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex greediness question
Message-Id: <b88s72$7ke9h$1@ID-184292.news.dfncis.de>

Gunnar Hjalmarsson wrote:
> How about this:
> 
>     $html =~ s[(<table>.*?</table>)][
>         my $table = $1;
>         if ($table =~ /$string/) {
>             # do something
>         } else {
>             $table;
>         }
>     ]egi;

Forgot the /s modifier. Should be:

     $html =~ s[(<table>.*?</table>)][
         my $table = $1;
         if ($table =~ /$string/) {
             # do something
         } else {
             $table;
         }
     ]egis;

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 24 Apr 2003 10:52:22 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Regex greediness question
Message-Id: <b8917n$9u7@onews.collins.rockwell.com>

On 4/24/2003 7:55 AM, Tman wrote:
> Am I misunderstanding something here?
> 
> C:\Temp>perl -de 1
> .....
>    DB<1> p "aaaaaabaaaaa" =~ /a(.*?b.*?)a/ 
> aaaaab
> 
> I was hoping to capture only "b" in the capture group.  By making
> both of the quantifiers non-greedy, it seems that the man page for
> perlre says that they will match the "minimum number of times
> possible".

Perl's regex engine returns the _first_ match it finds. Your regex isn't
anchored, so a match could happen anywhere in your target string, but
the RE engine will start looking at the beginning. 'aaaaab' is the first
string it finds that satisfies the expression.

> Well, this regex matches fine if both of the quantifiers match _zero_
> items.

Yes, that's *a* match, but it's not the *first* match.

> But the leftmost one wants to match more than the minimum.

Because that's the first match.

#!/usr/bin/perl
use strict;
use warnings;
use re 'debug';

'aaaaaabaaaaa' =~ /a(.*?b.*?)a/;
print "$1\n";

__END__
[ regex compilation info snipped ]
Matching REx `a(.*?b.*?)a' against `aaaaaabaaaaa'
  Setting an EVAL scope, savestack=3
   0 <> <aaaaaabaaaaa>    |  1:  EXACT <a>
   1 <a> <aaaaabaaaaa>    |  3:  OPEN1
   1 <a> <aaaaabaaaaa>    |  5:  MINMOD
   1 <a> <aaaaabaaaaa>    |  6:  STAR
  Setting an EVAL scope, savestack=3
                           REG_ANY can match 5 times out of 5...
   6 <aaaaaa> <baaaaa>    |  8:    EXACT <b>
   7 <aaaaaab> <aaaaa>    | 10:    MINMOD
   7 <aaaaaab> <aaaaa>    | 11:    STAR
  Setting an EVAL scope, savestack=3
   7 <aaaaaab> <aaaaa>    | 13:      CLOSE1
   7 <aaaaaab> <aaaaa>    | 15:      EXACT <a>
   8 <aaaaaaba> <aaaa>    | 17:      END
Match successful!
Freeing REx: `"a(.*?b.*?)a"'
aaaaab

> How could I make it such that only the "b" is matched in this regex.

The obvious answer is to not capture things you don't want.

'aaaaaabaaaaa' =~ /a.*?(b).*?a/;

> Trvial example, yes, but it is reduced from a real-world problem.  (I
> am trying to match the <TABLE>..... </TABLE> element in a page that
> contains a certain string, and only match that single table).

Ah. Now that's different. :) Don't try to hand roll a regex to parse
HTML. Take a look at HTML::Parser (on CPAN).

-mjc



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

Date: Thu, 24 Apr 2003 10:28:16 -0500
From: pooba53 <delautenschl@[nospam]wisc.edu>
Subject: Re: Still Stumped
Message-Id: <b88vqf$bdc$1@news.doit.wisc.edu>

You need to layoff the caffeine, man.
-Dan

Jay Tilton wrote:
> Stop top-posting replies, dammit.
> 
> pooba53 <delautenschl@[nospam]wisc.edu> wrote:
> : pooba53 wrote:
> : > I figured out using the:
> : > push ( @{$AllGenes{$gene}}, @range);
> : > 
> : > What I then used to get the unique elements was a chunk of code another
> : > gentleman posted a week or so ago that needed a tad bit of modification:
> : > 
> : > while (($key,$aref) = each %AllGenes)  {
> : >     @unique = grep !$seen{$_}++, map @$_, $aref;
> : >     $count = @unique;
> : >     print OUTPUT"$key:$count\n";
> : 
> : 
> : Can you tell me how I can account for $key if one is "CG3038" and 
> : another is "CG13038"? The algorithm works as long as one key is not a 
> : subset of another.
> 
> That makes no sense.
> 
> As hash keys, the strings "CG3038" and "CG13038" have nothing to do
> with each other.  Your meaning of "as long as one key is not a subset
> of another" is not transparent.
> 
> A short, complete program with sample data that exhibits the problem 
> would probably explain it better.  Be sure to say how its behavior
> differs from what you want; saying "does work" or "doesn't work" is a
> waste of good keystrokes.
> 



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

Date: Thu, 24 Apr 2003 17:04:09 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Still Stumped
Message-Id: <3ea818ef.90653823@news.erols.com>

pooba53 <delautenschl@[nospam]wisc.edu> wrote:

: You need to layoff the caffeine, man.

Thank you, good bye, and good luck.



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

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


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