[29910] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1153 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 3 03:40:20 2008

Date: Thu, 3 Jan 2008 00:40:13 -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           Thu, 3 Jan 2008     Volume: 11 Number: 1153

Today's topics:
        Parsing table in rtf file <ldolan@thinkinghatbigpond.net.au>
    Re: Parsing table in rtf file <skye.shaw@gmail.com>
    Re: Parsing table in rtf file <ldolan@thinkinghatbigpond.net.au>
        PERL + Repeat header on every page while printing excel venkatasatyasuresh@gmail.com
    Re: PERL + Repeat header on every page while printing e <ivan@0x4849.net>
    Re: PERL + Repeat header on every page while printing e <rkb@i.frys.com>
    Re: PERL + Repeat header on every page while printing e <hjp-usenet2@hjp.at>
        PERL CGI Script Responding to Link <mflll@wiu.edu>
    Re: PERL CGI Script Responding to Link <joost@zeekat.nl>
    Re: PERL CGI Script Responding to Link <usenet@larseighner.com>
    Re: PERL CGI Script Responding to Link <rkb@i.frys.com>
    Re: PERL CGI Script Responding to Link <hjp-usenet2@hjp.at>
    Re: Perl script to return the number of occurences of m davidfilmer@gmail.com
        Perl script to return the number of occurences of multi shane_melville@yahoo.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 30 Dec 2007 04:17:49 GMT
From: "Peter Jamieson" <ldolan@thinkinghatbigpond.net.au>
Subject: Parsing table in rtf file
Message-Id: <NZEdj.29080$CN4.23472@news-server.bigpond.net.au>

I am trying to extract data from the table in a large number of rtf files.
I tried RTF::Tokenizer and RTF::Parser but could not make progress
so have decided to try regular expressions.

My project is to get the tabular data into a db for further analysis.
My problem is that I cannot see how to parse the data rows so
that they match the correct field headings.

Any advice or suggestions appreciated!


###########################################
#  Perl code to parse table in rtf files  #
###########################################

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

use Time::Local;
use Win32::ODBC;
# use RTF::Tokenizer; # unsuccessful
# use RTF::Parser; # unsuccessful
use dbi;
use Getopt::Long;

 my $ett = localtime();
 print "\n Time : $ett \n";

 my $file_ = 'BURN_RDX_01.rtf';
 my @lines;

 open(INFO, $file_) || die("Unable to open file!");
 @lines = <INFO>;
 close(INFO);


 # get the useful line data
 my $line;
 my $useful_data;

 foreach $line (@lines) {
 if ($line =~ /\\pard\\intbl/) {
      $useful_data = "$useful_data.$line \n";
 }
 }
    print "useful_data are: $useful_data \n";


Inspection of the table headings reveals they may vary (sometimes no 
telemetry data for a particular range or table has different

ranges) but typical headings are like this:

\pard\intbl {\b\f1\fs24\qc Propellant Burn Times \cell }\pard\intbl 
{\f1\fs20\qc 22000m\par 20000m\cell
20000m\par 18000m\cell 18000m\par 16000m\cell 16000m\par 14000m\cell 
14000m\par 12000m\cell 12000m\par
10000m\cell 10000m\par 8000m\cell 8000m\par 6000m\cell 6000m\par 4000m\cell 
4000m\par 2000m\cell
2000m\par BURN CUT OFF\cell  }\pard\intbl {\b\f1\qc 17812\cell }\pard\intbl 
{\row }

There may be 6 to 30 data rows in the table, typical row looks like this:

\pard\intbl {\b\f1\fs20\qc  1\cell 40\cell  Composition (RDX1)\cell \b0\fs16 
\cell \b  \cell \cell
1319\cell [90]\cell 1293\cell [90]\cell 1321\cell [90]\cell 1273\cell 
[90]\cell 1245\cell [90]\cell
1173\cell [90]\cell 1117\cell [100]\cell 1102\cell [70]\cell 1119\cell 
[10]\cell 1218\cell [10]\cell
17817 \cell }\pard\intbl {\row }




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

Date: Sun, 30 Dec 2007 15:07:48 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: Parsing table in rtf file
Message-Id: <f51eccde-8c5d-444a-8cb0-bcdefe81c399@i7g2000prf.googlegroups.com>


Peter Jamieson wrote:
> I am trying to extract data from the table in a large number of rtf files.
> I tried RTF::Tokenizer and RTF::Parser but could not make progress
> so have decided to try regular expressions.

What problem(s) were you having with the RTF modules?

I know looking at RTF can be fun and all, but why hammer out some
regexes to parse RTF
when a module already exists for this?

> My project is to get the tabular data into a db for further analysis.
> My problem is that I cannot see how to parse the data rows so
> that they match the correct field headings.
>
> Any advice or suggestions appreciated!

Not familiar with the format's tokens, but from looking at it quickly,
it appears as though the type of token is given after the text
portion, so you can try something like:

#your sub class of RTF::Parser
#not tested

my $tables = [];
my $cells = [];
my $rows = [];

my $token;

#define tokens...


sub text {
     $token = $_[1];
}


my %do_on_control = (

    '__DEFAULT__' => sub {

      my ( $self, $type, $arg ) = @_;

      if($arg) {
         if($arg eq $CELL_END ) {
           push @$cells, $tok;
         }
         elsif($arg eq $ROW_END ) {
           push @$rows, $cells;
           $cells = []
         }
         elsif($arg eq $TABLE_END ) {
           push @$tables, $rows;
           $rows = []
         }

      }
     });

sub parse
{
  my ($self,$file) = @_;
  $self->control_definition( \%do_on_control );
  open(my $IN,$file) || die $!;
  $self->parse_stream($IN);
  close($IN);

  $tables;
}



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

Date: Mon, 31 Dec 2007 03:04:54 GMT
From: "Peter Jamieson" <ldolan@thinkinghatbigpond.net.au>
Subject: Re: Parsing table in rtf file
Message-Id: <q%Ydj.29394$CN4.21222@news-server.bigpond.net.au>


"Skye Shaw!@#$" <skye.shaw@gmail.com> wrote in message 
news:f51eccde-8c5d-444a-8cb0-bcdefe81c399@i7g2000prf.googlegroups.com...
>
> Peter Jamieson wrote:
>> I am trying to extract data from the table in a large number of rtf 
>> files.
>> I tried RTF::Tokenizer and RTF::Parser but could not make progress
>> so have decided to try regular expressions.
>
> What problem(s) were you having with the RTF modules?
>
> I know looking at RTF can be fun and all, but why hammer out some
> regexes to parse RTF
> when a module already exists for this?
>
>> My project is to get the tabular data into a db for further analysis.
>> My problem is that I cannot see how to parse the data rows so
>> that they match the correct field headings.
>>
>> Any advice or suggestions appreciated!
>
> Not familiar with the format's tokens, but from looking at it quickly,
> it appears as though the type of token is given after the text
> portion, so you can try something like:
>
> #your sub class of RTF::Parser
> #not tested
>
> my $tables = [];
> my $cells = [];
> my $rows = [];
>
> my $token;
>
> #define tokens...
>
>
> sub text {
>     $token = $_[1];
> }
>
>
> my %do_on_control = (
>
>    '__DEFAULT__' => sub {
>
>      my ( $self, $type, $arg ) = @_;
>
>      if($arg) {
>         if($arg eq $CELL_END ) {
>           push @$cells, $tok;
>         }
>         elsif($arg eq $ROW_END ) {
>           push @$rows, $cells;
>           $cells = []
>         }
>         elsif($arg eq $TABLE_END ) {
>           push @$tables, $rows;
>           $rows = []
>         }
>
>      }
>     });
>
> sub parse
> {
>  my ($self,$file) = @_;
>  $self->control_definition( \%do_on_control );
>  open(my $IN,$file) || die $!;
>  $self->parse_stream($IN);
>  close($IN);
>
>  $tables;
> }
>

Thanks for the input Skye!
I read up all I could find on the rtf parsing and tokenizing modules
and came to the conclusion that they were good for text data but
not well suited to tabular data. However I would be more than happy
to be proven wrong!. I can get the header and footer info from the
rtf files OK into a db but could not make progress with the tabular
data. The sticking point was getting the data rows to line up with the
field headings. I had previously used VBA code in MS Excel and MS Word
for this project but file bloat and unreliability has me searching for a
Perl solution.
I will have a close look at your suggestions asap.
Thanks for your help...very much appreciated!...all the best for 2008!
 ...cheers, Peter 




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

Date: Fri, 28 Dec 2007 04:13:08 -0800 (PST)
From: venkatasatyasuresh@gmail.com
Subject: PERL + Repeat header on every page while printing excel
Message-Id: <28f73260-9f4b-408b-825c-beb6d709763e@d4g2000prg.googlegroups.com>

Hi,
       I am working on an application using PERL 5.8.

       I have a requirement where i am getting data from Oracle
database & exporting it to an excel. Users will print this excel file.
We are getting bulk data from database & its printing multiple pages.
On every page we want the header to be present.

       Printing the excel file is done manually from the exported
excel. But when he prints the excel, header should repeat on each
page.

      Somehow we have found doing this in excel. from File -> page set
up -> Sheet tab, we have to select rows to repeat at top.

       But we want this to be done programmatically from PERL. I mean
to say when I export the data to excel file, this file should have
this setting (rows to repeat at top i have to set programmatically).

       I can't request the end-user to do this manually.

      So any input on this would be great help to me.

Thanks
Suresh


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

Date: Fri, 28 Dec 2007 06:32:04 -0800 (PST)
From: Ivan Novick <ivan@0x4849.net>
Subject: Re: PERL + Repeat header on every page while printing excel
Message-Id: <2dc71eb8-4c90-4ce6-b6a7-8d37d11f0eae@j20g2000hsi.googlegroups.com>

On Dec 28, 4:13 am, venkatasatyasur...@gmail.com wrote:
> Hi,
>        I am working on an application using PERL 5.8.
>
>        I have a requirement where i am getting data from Oracle
> database & exporting it to an excel. Users will print this excel file.
> We are getting bulk data from database & its printing multiple pages.
> On every page we want the header to be present.

I am hoping you are printing to excel in csv plain text format and not
using binary api specifically for excel.

If you are printing in csv format and want to repeat a header on every
page you can use "perl format" to do this:

http://perldoc.perl.org/functions/format.html

Regards,
Ivan Novick
http://www.0x4849.net


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

Date: Fri, 28 Dec 2007 08:54:56 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: PERL + Repeat header on every page while printing excel
Message-Id: <89700ca6-3400-4a69-9a0f-01880b348aa4@s8g2000prg.googlegroups.com>

On Dec 28, 6:32 am, Ivan Novick <i...@0x4849.net> wrote:
> On Dec 28, 4:13 am, venkatasatyasur...@gmail.com wrote:
>
> > Hi,
> >        I am working on an application using PERL 5.8.
>
> >        I have a requirement where i am getting data from Oracle
> > database & exporting it to an excel. Users will print this excel file.
> > We are getting bulk data from database & its printing multiple pages.
> > On every page we want the header to be present.
>
> I am hoping you are printing to excel in csv plain text format and not
> using binary api specifically for excel.
Why?
>
> If you are printing in csv format and want to repeat a header on every
> page you can use "perl format" to do this:
>
> http://perldoc.perl.org/functions/format.html

Using an api would give you far more control over the spreadsheet
formatting than the "perl format"

Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file.
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spreadsheet/WriteExcel.pm#repeat_rows($first_row,_$last_row)


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

Date: Sun, 30 Dec 2007 17:41:20 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: PERL + Repeat header on every page while printing excel
Message-Id: <slrnfnfihj.qlr.hjp-usenet2@hrunkner.hjp.at>

On 2007-12-28 16:54, Ron Bergin <rkb@i.frys.com> wrote:
> On Dec 28, 6:32 am, Ivan Novick <i...@0x4849.net> wrote:
>> On Dec 28, 4:13 am, venkatasatyasur...@gmail.com wrote:
>> >        I am working on an application using PERL 5.8.

<mantra>
    The language is spelled "Perl", not "PERL".
</mantra>

>> >        I have a requirement where i am getting data from Oracle
>> > database & exporting it to an excel. Users will print this excel file.

What is the purpose of the export?

* To get an Excel file, which people can use for further processing of
  the data (compute statistics, make graphs, etc.) and incidentally also 
  print.

* To print the data.

If it is the latter, then creating a "print file" of some sort (e.g.,
Postscript or PDF, or maybe just plain text) may be a better way,
especially if precise control over the layout is necessary.


>> > We are getting bulk data from database & its printing multiple pages.
>> > On every page we want the header to be present.
>>
>> I am hoping you are printing to excel in csv plain text format and not
>> using binary api specifically for excel.
> Why?

I was going to ask the same thing. In this case CSV is completely
unsuitable as you have absolutely no control over the layout. A CSV file
contains only the data, nothing else.


>> If you are printing in csv format and want to repeat a header on every
>> page you can use "perl format" to do this:
>>
>> http://perldoc.perl.org/functions/format.html

How much is "a page" in CSV? You don't know, or rather, you *do* know
that there is no such thing as a "page" in CSV. The first line may be
header line, but all other lines are supposed to contain only data. You
should not repeat header lines periodically in a CSV file.

Also, "format" is intended for fixed width layouts, which CSV isn't.
If you want to write CSV, DBD::CSV or Text::CSV is probably the way to
go (or just use simple print statements).


> Using an api would give you far more control over the spreadsheet
> formatting than the "perl format"
>
> Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file.

Right. Or - if the real objective is printing instead of creating an
Excel file - PDF::API2.

	hp



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

Date: Sat, 29 Dec 2007 08:44:11 -0800 (PST)
From: "Dr. Leff" <mflll@wiu.edu>
Subject: PERL CGI Script Responding to Link
Message-Id: <6407a7b3-9e5f-4765-bb23-5b5fe3c9e71e@i72g2000hsd.googlegroups.com>

I wrote a web site in Perl CGI.   One of the familiar tasks in many
web sites
is validating new users.  Traditionally, they enter their email,
desired login
and password.  The system sends a confirmation email with a link on
which
to click.  The user checks their email, clicks and the system knows
they
are a "real" person.

My web systems send a message like this after the user enters their
desired
login, email address and the demographic information we want:
I aped the format used when one clicks
the submit  button on a form.

<A href="http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c">
Please click here to confirm your login or go to
http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c</A>

__________________________________________________________________________
But, when I click on it, it calls confirm.scgi as we expect.
Unfortunately, the parameters are not
passed in the standard input.

The beginning of the script, confirm.scgi is instrumented for
debugging
as follows.
Observe that there is no data in STDIN.

#!/usr/local/bin/perl
require "/home/mflll/http/2/ll.pm";
use IO::Handle;
open (out,">".ll::FN("debugconfirm.out"));
out->autoflush(1);
print "Content-type: text/html\n\n";
print "<HTML>";
print "$ENV{'BASE'}<HEAD>";
print "<TITLE>Confirm Login </TITLE>";
print "</HEAD>";
print "<BODY>";
print out "in confirm\n";
## get the login id and Confirmation Code, which should be in the CGI
## query string
print out "standard input |".<STDIN>."|\n";

The output is as follows:

in confirm
standard input ||


Normally, when I read information from a form in a perl CGI script, I
use
a loop to read the standard information.  This does matches against
the
parameter names to extract the contents.  When I tried this (see code
below),
I got no information -- and debugging showed that it did not enter the
loop.

while (<STDIN>) {
   print out "confirming standard input |".$_."|\n";
   if (/LoginID=([^&]+)/) {
     $login = $1;
   }
   if (/C=([^&]+)/) {
     $Code = $1;
   }
}

Any help would be greatly appreciated:

Dr. Laurence Leff  Western Illinois University, Macomb IL 61455 ||
(309) 298-1315
Stipes 447 Assoc. Prof. of Computer Sci. Pager: 309-367-0787 FAX:
309-298-2302


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

Date: Sat, 29 Dec 2007 18:24:30 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: PERL CGI Script Responding to Link
Message-Id: <87r6h52z3l.fsf@zeekat.nl>

"Dr. Leff" <mflll@wiu.edu> writes:

> I wrote a web site in Perl CGI.   One of the familiar tasks in many
> web sites
> is validating new users.  Traditionally, they enter their email,
> desired login
> and password.  The system sends a confirmation email with a link on
> which
> to click.  The user checks their email, clicks and the system knows
> they
> are a "real" person.
>
> My web systems send a message like this after the user enters their
> desired
> login, email address and the demographic information we want:
> I aped the format used when one clicks
> the submit  button on a form.
>
> <A href="http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c">
> Please click here to confirm your login or go to
> http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c</A>
>
> __________________________________________________________________________
> But, when I click on it, it calls confirm.scgi as we expect.
> Unfortunately, the parameters are not
> passed in the standard input.


That's because parameters in the URL are not sent to a CGI script via
STDIN since they're not in the /body/ of the HTTP request. See the CGI specs.
RFC 3875, section 4.1.7 in particular.

In general, though, you're /much/ better off using the standard CGI
module since it automatically handles this issue and much more.

http://perldoc.perl.org/CGI.html

HTH,
Joost.






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

Date: 29 Dec 2007 19:40:44 GMT
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: PERL CGI Script Responding to Link
Message-Id: <slrnfnd8iq.l49.usenet@debranded.larseighner.com>

In our last episode, 
<6407a7b3-9e5f-4765-bb23-5b5fe3c9e71e@i72g2000hsd.googlegroups.com>, 
the lovely and talented Dr. Leff 
broadcast on comp.lang.perl.misc:

> I wrote a web site in Perl CGI.   One of the familiar tasks in many web
> sites is validating new users.  Traditionally, they enter their email,
> desired login and password.  The system sends a confirmation email with a
> link on which to click.  The user checks their email, clicks and the
> system knows they are a "real" person.

So, you suppose a mailreader is a web browser?  Why would you do that?

-- 
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
                         Countdown: 387 days to go.


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

Date: Sat, 29 Dec 2007 12:18:49 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: PERL CGI Script Responding to Link
Message-Id: <00b696dd-4673-47af-8a50-8e9ef0d9fdf8@e6g2000prf.googlegroups.com>

On Dec 29, 8:44 am, "Dr. Leff" <mf...@wiu.edu> wrote:
> I wrote a web site in Perl CGI.   One of the familiar tasks in many
> web sites
> is validating new users.  Traditionally, they enter their email,
> desired login
> and password.  The system sends a confirmation email with a link on
> which
> to click.  The user checks their email, clicks and the system knows
> they
> are a "real" person.
>
> My web systems send a message like this after the user enters their
> desired
> login, email address and the demographic information we want:
> I aped the format used when one clicks
> the submit  button on a form.
>
> <A href="http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c">
> Please click here to confirm your login or go tohttp://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c</A>
>
> __________________________________________________________________________
> But, when I click on it, it calls confirm.scgi as we expect.
> Unfortunately, the parameters are not
> passed in the standard input.
>
> The beginning of the script, confirm.scgi is instrumented for
> debugging
> as follows.
> Observe that there is no data in STDIN.
>
> #!/usr/local/bin/perl
> require "/home/mflll/http/2/ll.pm";
> use IO::Handle;
> open (out,">".ll::FN("debugconfirm.out"));
You should always check the return value of an open call.  Nowdays
it's preferable to use the 3 arg form of open and a lexical var for
the filehandle.

open (my $out, '>', ll::FN("debugconfirm.out") ) or die $!;

> out->autoflush(1);
$out->autoflush(1);

> print "Content-type: text/html\n\n";
> print "<HTML>";
> print "$ENV{'BASE'}<HEAD>";
> print "<TITLE>Confirm Login </TITLE>";
> print "</HEAD>";
> print "<BODY>";

Why the multiple pront statements?
What is in $ENV{'BASE'} and does it need to be in the head section?
The use of the CGI module could simplify this.

use CGI;
my $cgi = CGI->new;  # I prefer the OO style instead of the
functional.
my %vars = $cgi->Vars; # fetch the params and place them in a hash.

print $cgi->header,  # If needed, $ENV{'BASE'} could be added
      $cgi->start_html('Confirm Login');

> print out "in confirm\n";
> ## get the login id and Confirmation Code, which should be in the CGI
> ## query string
> print out "standard input |".<STDIN>."|\n";

print $out "standard input | $vars{'C'} |\n";

>
> The output is as follows:
>
> in confirm
> standard input ||
>
> Normally, when I read information from a form in a perl CGI script, I
> use
> a loop to read the standard information.  This does matches against
> the
> parameter names to extract the contents.  When I tried this (see code
> below),
> I got no information -- and debugging showed that it did not enter the
> loop.
>
> while (<STDIN>) {
>    print out "confirming standard input |".$_."|\n";
>    if (/LoginID=([^&]+)/) {
>      $login = $1;
>    }
>    if (/C=([^&]+)/) {
>      $Code = $1;
>    }
>
> }
>
No need to manually do that yourself, and as you've discovered it's
easy to do it incorrectly and not get the desired results.  Use the
CGI module!


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

Date: Sun, 30 Dec 2007 17:48:51 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: PERL CGI Script Responding to Link
Message-Id: <slrnfnfivm.qlr.hjp-usenet2@hrunkner.hjp.at>

On 2007-12-29 19:40, Lars Eighner <usenet@larseighner.com> wrote:
> In our last episode, 
><6407a7b3-9e5f-4765-bb23-5b5fe3c9e71e@i72g2000hsd.googlegroups.com>, 
> the lovely and talented Dr. Leff 
> broadcast on comp.lang.perl.misc:
>
>> I wrote a web site in Perl CGI.   One of the familiar tasks in many web
>> sites is validating new users.  Traditionally, they enter their email,
>> desired login and password.  The system sends a confirmation email with a
>> link on which to click.  The user checks their email, clicks and the
>> system knows they are a "real" person.
>
> So, you suppose a mailreader is a web browser?

No, he doesn't. He merely supposes that the user receiving the mail is
able to invoke a web browser. Since that person just tried to register
themselves at a web site, this is not an unreasonable assumption.

	hp



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

Date: Sat, 29 Dec 2007 15:31:24 -0800 (PST)
From: davidfilmer@gmail.com
Subject: Re: Perl script to return the number of occurences of multiple lines  in a file
Message-Id: <71cfc234-1bf0-4498-9c0c-c1e49d63679e@e23g2000prf.googlegroups.com>

On Dec 29, 3:13 pm, shane_melvi...@yahoo.com wrote:
> I am trying to write a script to return the number of occurences of
> certain text/lines/strings in a file.

perldoc -q count

     How can I count the number of occurrences of a substring
          within a string?

> If anyone can help out drop me a mail

No.  That's not how usenet works.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Sat, 29 Dec 2007 15:13:54 -0800 (PST)
From: shane_melville@yahoo.com
Subject: Perl script to return the number of occurences of multiple lines in a  file
Message-Id: <43921e51-4ca4-43a9-b101-bdbe626852a2@s27g2000hsb.googlegroups.com>

Hi

I am trying to write a script to return the number of occurences of
certain text/lines/strings in a file. The text is as follows:

Create:subscriber,.........................................................................................................
(blank line)
# sub:success

I have tried the following but it does not work. I am trying to treat
the lines as a string starting with

/Create:subscriber/../sub:success/

but this has not worked. These lines must be together

This is what I have written so far but it does not return the correct
lines

#!/usr/bin/env perl

#use strict;
#use warnings;
sub getlines();
sub getlines1();
my @lines;
my @lines1;
my $lines_ref;
my $lines_ref1;
my $count;
my $count1;
$lines_ref=getlines();
$lines_ref1=getlines1();
@lines=@$lines_ref;
@lines1=@$lines_ref1;
$count=@lines;
$count1=@lines1;
print "The total  sub:success count for the  file  is : $count\n\n
The sub:success strings from the file are as follows: \n\n";
#print join "\n",@lines;

print join "\n",@lines1;
print "The total count for the create subscriber commands is :
$count1\n\n
The create subscriber strings from the file are as follows: \n\n";
#print join "\n",@lines1;

sub getlines()
{
    my $file='/data/log/success.log;
    open FILE, $file or die "FILE $file NOT FOUND - $!\n";
    my @contents=<FILE>;
    my @filtered=grep(/sub:success/,@contents);
    return \@filtered;

}
sub getlines1()
{
     my $file='/data/log/success.log';
     my $file='shane.txt';
     open FILE, $file or die "FILE $file NOT FOUND - $!\n";
     my @contents=<FILE>;
     my @filtered1=grep(/Create:subscriber/../sub:success/,@contents);
  #   my @filtered2=grep(/Create:subscriber/, @contents);
  #   my @filtered2=grep(/sub:success /,@contents);
     return \@filtered1;
}


If anyone can help out drop me a mail

Shane


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

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


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