[23096] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5317 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 5 14:31:24 2003

Date: Tue, 5 Aug 2003 11:30:55 -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           Tue, 5 Aug 2003     Volume: 10 Number: 5317

Today's topics:
        parsing log in multiple passes (disco)
    Re: parsing log in multiple passes <krahnj@acm.org>
    Re: pattern matching (brian liu)
        perl  DBI (sangeetha)
    Re: perl  DBI (Tad McClellan)
    Re: perl  DBI <no_thanks@bms.umist.ac.uk>
    Re: Perl - how to compute totals via hash request (shree)
    Re: Perl - how to compute totals via hash request (Tad McClellan)
        Perl -> XML <a@viot.de>
    Re: Perl -> XML <usenet@expires082003.tinita.de>
    Re: Perl -> XML <newsguy@xmltwig.com>
        Perl as embedded scripting language <ivomirb@hotmail.com>
    Re: Perl as embedded scripting language <vernaza@force.stwing.upenn.edu>
    Re: Perl as embedded scripting language (Sam Holden)
        Perl back-end for Macromedia Petstore example (Simon)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 3 Aug 2003 16:21:45 -0700
From: jpdiscover@hotmail.com (disco)
Subject: parsing log in multiple passes
Message-Id: <9b579c86.0308031521.359d2dd4@posting.google.com>

I have output from a CLI that I am parsing into a data structure
(hash) to be used as input to another program which reads the hash. 
The CLI always formats the data in the same by first listing the card
information followed by information for each port.

I have figured out the routine to parse all of the data into a hash,
but what I can't figure out is how to do determine the unique key
value first by considering all of the CLI output and then use it as I
build the hash.  There is probably a better way to avoid rewinding the
file as I've done too.

Right now I just use the Node Id, but I really need my unique key to
be based on the following criteria:

1) If the "node id" <> 0's then use the Node ID as the unique
identifier.
2) If the "node id" == 0's then use the port id with the smallest
alpha value (it is in hex) as the unique identifier.

<cli.log>

  Card name           : SuperWombat
  Firmware Version    : 4.234
  Driver Version      : 7.2345
  Node Id             : 00000
  Number of Ports     : 2

      Port Id         : 1a3c5f
      Port name       : Alpha
      Port type       : Ethernet
      Port speed      : 10

      Port Id         : af2c2d2
      Port name       : Alpha2
      Port type       : Scsi
      Port speed      : 1gig

  Card name           : BitBlaster
  Firmware Version    : 5.000
  Driver Version      : 8.000 rel 5.02
  Node Id             : 24550
  Number of Ports     : 1

      Port Id         : 10200
      Port name       : GigE1
      Port type       : Ethernet
      Port speed      : 1000

Ideal output (understanding that in real life the hash doesn't come
out in order -- that doesn't matter, and that "->" is simply for
presentation and not part of data)

1a3c5f -> Card name -> SuperWombat
1a3c5f -> Firmware Version -> 4.234
1a3c5f -> Driver Version -> 7.2345
1a3c5f -> Node Id -> 00000
1a3c5f -> Number of Ports -> 2
1a3c5f -> 0 -> Port Id -> 1a3c5f
1a3c5f -> 0 -> Port name -> Alpha
1a3c5f -> 0 -> Port type -> Ethernet
1a3c5f -> 0 -> Port speed -> 10
1a3c5f -> 1 -> Port Id -> af2c2d2
1a3c5f -> 1 -> Port name -> Alpha2
1a3c5f -> 1 -> Port type -> Scsi
1a3c5f -> 1 -> Port speed -> 1gig
24550 -> Card name -> BitBlaster
24550 -> Firmware Version -> 5.000
24550 -> Driver Version -> 8.000 rel 5.02
24550 -> Node Id -> 24550
24550 -> Number of Ports -> 1
24550 -> 0 -> Port Id -> 10200
24550 -> 0 -> Port name -> GigE1
24550 -> 0 -> Port type -> Ethernet
24550 -> 0 -> Port speed -> 1000


Can anyone suggest a way to do this easily?  I have spent alot of time
trying to push/pop/sort arrays, but I can't pull the whole thing
together.  I know this can be done in Perl, but I am stuck.

Thanks!
Disco

following is my code that shows what I have done so far...

#!/usr/bin/perl
use strict;

my $line;       # Scalar to hold line from log file being processed.
my $card_hash = {}; #anonymous hash (data structure)
my $card_key;   # Primary key
my $tkey;       # Sub key
my $tval;       # Value

my $port_count = 0;

my @temp;
my @card_tag;

open (DATA, "cli.log")or die("Cannot open: filename $!");

# Find node_wwn's to use as a unique identifier for each card.
# Create an array of node WWN's found and then rewind the file and
start again.
#

while (<DATA>)
{
    chomp;
    push @temp,  $_ if /Node Id/;  # get the entire line if it
contains "Node Id" and add it to array
}

foreach $line (@temp) # assign each item in list (array) to $line and
process
{
    $line =~ /(.*?):(.*)/;    # Delimiter ==>   " : "
	$tval = $2;
	$tval =~ s/^\s+//g; 
	$tval =~ s/\s+$//g;
    push @card_tag, $tval;
}

#rewind data file to beginning for second pass
seek (DATA, 0, 0);

# During second pass, "shift" the next (first) node from the array of
"card_tags" and use it
# as a unique identifier.  Trigger "shift" based on line indicating
each new card from CLI.
# New card's currently start with "Card name"

while ($line = <DATA>) 
    {
    if ($line =~ /Card name/)
        {
            $port_count = -1;  # zero based port count
            $card_key = shift @card_tag;
        }
     if ($line =~ /Port Id/)
        {
            $port_count++;
        }
 
    chomp($line);
    $line =~ /(.*?):(.*)/;    # Delimiter ==>   " : "
	$tkey = $1;
	$tval = $2;

    $tkey =~ s/^\s+//g; # Strip leading spaces from value
    $tkey =~ s/\s+$//g; # Strip trailing spaces from value
    
	$tval =~ s/^\s+//g; 
	$tval =~ s/\s+$//g;
	
	$tval = "N/A" if (!$tval);  # If "tval" is empty, assign value of
"N/A"
    
    if ($port_count > -1)  # Record port value
        {
            $card_hash->{$card_key}->{$port_count}->{$tkey}="$tval" if
$tkey;  #Load key & value; If blank line skip.
        }
    else  # No port value
        {
            $card_hash->{$card_key}->{$tkey}="$tval" if $tkey;  #Load
key & value; If blank line skip.
        }
  }

#Print hash to verfiy correct construction.
print_hash($card_hash);

###########################################################
# Print hash as deep as: 
# $pri_key=$sub_key=$sub_sub_key=$pri_hash->{$pri_key}->{$sub_key}->{$sub_sub_key}
sub print_hash 
{
    my ($pri_hash) = @_ ; 
        
    foreach my $pri_key ( keys %{$pri_hash} ) 
    {
        foreach my $sub_key ( keys %{ $pri_hash->{$pri_key} } )
        {
            if (ref($pri_hash->{$pri_key}->{$sub_key}) eq 'HASH' ) # ?
"value" | embedded hash
            {
                foreach my $sub_sub_key ( keys %{
$pri_hash->{$pri_key}->{$sub_key} } )
                {
                    print "$pri_key = $sub_key = $sub_sub_key =
$pri_hash->{$pri_key}->{$sub_key}->{$sub_sub_key}\n";
                }
            }
            else
               { 
                    print "$pri_key = $sub_key =
$pri_hash->{$pri_key}->{$sub_key}\n";
               }
           }
    }
}


__END__

<cli.log>

  Card name           : SuperWombat
  Firmware Version    : 4.234
  Driver Version      : 7.2345
  Node Id             : 00000
  Number of Ports     : 2

      Port Id         : 1a3c5f
      Port name       : Alpha
      Port type       : Ethernet
      Port speed      : 10

      Port Id         : af2c2d2
      Port name       : Alpha2
      Port type       : Scsi
      Port speed      : 1gig

  Card name           : BitBlaster
  Firmware Version    : 5.000
  Driver Version      : 8.000 rel 5.02
  Node Id             : 24550
  Number of Ports     : 1

      Port Id         : 10200
      Port name       : GigE1
      Port type       : Ethernet
      Port speed      : 1000


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

Date: Mon, 04 Aug 2003 19:48:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: parsing log in multiple passes
Message-Id: <3F2EB8DC.105277AF@acm.org>

disco wrote:
> 
> I have output from a CLI that I am parsing into a data structure
> (hash) to be used as input to another program which reads the hash.
> The CLI always formats the data in the same by first listing the card
> information followed by information for each port.
> 
> I have figured out the routine to parse all of the data into a hash,
> but what I can't figure out is how to do determine the unique key
> value first by considering all of the CLI output and then use it as I
> build the hash.  There is probably a better way to avoid rewinding the
> file as I've done too.
> 
> Right now I just use the Node Id, but I really need my unique key to
> be based on the following criteria:
> 
> 1) If the "node id" <> 0's then use the Node ID as the unique
> identifier.
> 2) If the "node id" == 0's then use the port id with the smallest
> alpha value (it is in hex) as the unique identifier.
> 
> <cli.log>
> 
>   Card name           : SuperWombat
>   Firmware Version    : 4.234
>   Driver Version      : 7.2345
>   Node Id             : 00000
>   Number of Ports     : 2
> 
>       Port Id         : 1a3c5f
>       Port name       : Alpha
>       Port type       : Ethernet
>       Port speed      : 10
> 
>       Port Id         : af2c2d2
>       Port name       : Alpha2
>       Port type       : Scsi
>       Port speed      : 1gig
> 
>   Card name           : BitBlaster
>   Firmware Version    : 5.000
>   Driver Version      : 8.000 rel 5.02
>   Node Id             : 24550
>   Number of Ports     : 1
> 
>       Port Id         : 10200
>       Port name       : GigE1
>       Port type       : Ethernet
>       Port speed      : 1000
> 
> Ideal output (understanding that in real life the hash doesn't come
> out in order -- that doesn't matter, and that "->" is simply for
> presentation and not part of data)
> 
> 1a3c5f -> Card name -> SuperWombat
> 1a3c5f -> Firmware Version -> 4.234
> 1a3c5f -> Driver Version -> 7.2345
> 1a3c5f -> Node Id -> 00000
> 1a3c5f -> Number of Ports -> 2
> 1a3c5f -> 0 -> Port Id -> 1a3c5f
> 1a3c5f -> 0 -> Port name -> Alpha
> 1a3c5f -> 0 -> Port type -> Ethernet
> 1a3c5f -> 0 -> Port speed -> 10
> 1a3c5f -> 1 -> Port Id -> af2c2d2
> 1a3c5f -> 1 -> Port name -> Alpha2
> 1a3c5f -> 1 -> Port type -> Scsi
> 1a3c5f -> 1 -> Port speed -> 1gig
> 24550 -> Card name -> BitBlaster
> 24550 -> Firmware Version -> 5.000
> 24550 -> Driver Version -> 8.000 rel 5.02
> 24550 -> Node Id -> 24550
> 24550 -> Number of Ports -> 1
> 24550 -> 0 -> Port Id -> 10200
> 24550 -> 0 -> Port name -> GigE1
> 24550 -> 0 -> Port type -> Ethernet
> 24550 -> 0 -> Port speed -> 1000
> 
> Can anyone suggest a way to do this easily?  I have spent alot of time
> trying to push/pop/sort arrays, but I can't pull the whole thing
> together.  I know this can be done in Perl, but I am stuck.


This produces your "Ideal output" format although it doesn't use a hash:

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

my $file = 'cli.log';
open my $fh, '<', $file or die "Cannot open $file: $!";

local $/ = '';   # paragraph mode
my @data;
while ( <$fh> ) {
    my ( @temp, $nkey, $ports );
    for my $line ( grep [ s/^\s+//, s/\s+$// ], split /\n/ ) {
        my ( $key, $val ) = grep [ s/^\s+//, s/\s+$// ], split /:/, $line, 2;
        $nkey  = $val if $key eq 'Node Id' and $val != 0;
        $ports = $val if $key eq 'Number of Ports';
        push @temp, [ $key, $val ];
        }

    my @nkeys;
    for my $port ( 1 .. $ports ) {
        for my $line ( grep [ s/^\s+//, s/\s+$// ], split /\n/, <$fh> ) {
            my ( $key, $val ) = grep [ s/^\s+//, s/\s+$// ], split /:/, $line, 2;
            push @nkeys, $val if $key eq 'Port Id';
            push @temp, [ $port - 1, $key, $val ];
            }
        }
    @nkeys = sort @nkeys;

    unshift @$_, defined $nkey ? $nkey : $nkeys[ 0 ] for @temp;
    push @data, @temp;
    }

print join( ' -> ', @$_ ), "\n" for @data;

__END__


If you need the data in a hash this will do it.

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $file = 'cli.log';
open my $fh, '<', $file or die "Cannot open $file: $!";

local $/ = '';   # paragraph mode
my %data;
while ( <$fh> ) {
    my %temp = grep [ s/^\s+//, s/\s+$// ], split /:|\n/;

    my ( @keys, @ports );
    for my $port ( 1 .. $temp{ 'Number of Ports' } ) {
        push @ports, { grep [ s/^\s+//, s/\s+$// ], split /:|\n/, <$fh> };
        push @keys, $ports[ -1 ]{ 'Port Id' };
        }
    @keys = sort @keys;

    if ( $temp{ 'Node Id' } == 0 ) {
        $data{ $keys[ 0 ] } = { %temp, map { $_, $ports[ $_ ] } 0 .. $#ports };
        }
    else {
        $data{ $temp{ 'Node Id' } } = { %temp, map { $_, $ports[ $_ ] } 0 .. $#ports };
        }
    }

print Dumper( \%data );

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 4 Aug 2003 12:24:17 -0700
From: xliu75@yahoo.com (brian liu)
Subject: Re: pattern matching
Message-Id: <89796311.0308041124.118d3e36@posting.google.com>

Kjetil Skotheim <kjetilskotheim@yahoo.com> wrote in message news:<oprs7lfzdx85yxzq@nntp.uio.no>...
> Have you looked at the HTML::TableExtract module?
> 
> Or you might parse one-dimentional <table>'s just like this:
> Or I sometimes use the following sub to extract html-<table>'s
> and copy the non-html-content inside <td>-tags into
> a list of lists. (Two-dim-perl-array).
> 
> 
> my $html=<<"END";
>   <html>
>   ...
>   The table:
>   <table>
>   <tr><td><b>Now:</b></td> <td>234</td> <td>11</td></tr>
>   <tr><td><b>Then:</b></td> <td><a href="asdf">ABC</a></td></tr>
>   <tr><td>After:</td><td>1</td><td>2</td><td>3<td>4<td>5</tr>
>   </table>
>   </html>
> END
>  my @table = ht2t($html);  #Or ht2t($html,'table:'); #string before right 
> <table>
> for (@table){ print map "($_) ",@$_; print "\n" }
>  sub ht2t {    # = html-table-to-table
>   my($f,$s)=@_;
>   $f=~s,.*?($s).*?(<table.*?)</table.*,$2,si;
>   my $e=0;$e++ while index($f,$s=chr($e))>=$[;
>   $f=~s/<t(d|r|h).*?>/$1$s/gsi;
>   $f=~s/\s*<.*?>\s*//gsi;
>   my @t=split("r$s",$f);shift @t;
>   for (@t){my @r=split(/[dh]$s/,$_);shift @r;$_=[@r]}
>   @t;
> }
> __END__
> 
> 
> This prints, as expected:
> 
> (Now:) (234) (11) (Then:) (ABC)
> (After:) (1) (2) (3) (4) (5)
> 
> 

I think this one can work.

here is another solution:
$defaultDir='c:\haha';
$inputFile='pop\d+\.htm';
#$/="";
#$/ = '<HTML>';
#package CPath::WebApp;

#Output files
$tempOutput = $defaultDir.'\tempOutput.txt';

#Clear files
unlink $tempOutput;

main($defaultDir);


sub main()
{
	#$err= opendir THISDIR,$_[0];
	if( ! opendir THISDIR,$_[0] ) {
		print "Faild to open $_[0]\n";
		die;
	}

	
	my @dataFiles = grep /$inputFile/ , readdir THISDIR;		# Get all
data.* files
	closedir THISDIR;
	openFiles();
	
	sort @dataFiles;
	foreach $file (@dataFiles){
		processFile($file);
	}
	
	closeFiles();
print "Done.\n";
	
}#main


sub processFile()
{

	local $path=$defaultDir;
	local $dataF = $_[0];
	print "Processing $_[0] ...\n";
	
	 $count=1;
	open DF,$path.'/'.$dataF or print "Error opening file $dataF, at
$path \n Error: $!\n";
	while(<DF>){
		
		if(/^$/){next;}
		if ($count<5){
	       
	if(/<TD>(.*?)<\/TD> <TD>(.*?)<\/TD>/){
	   @a[$count]=$1; 
	   @a[$count+1]=$2; 
	      
	   print "$count @a[$count] \t";
	   print "$count+1 @a[$count+1] \t";
	   $count+=2;
	   next;
	}

	if(/<TD>(.*?)<\/TD>/){
	   @a[$count]=$1; 
	      
	   print "$count @a[$count] \t";
	   $count++;
	}
	 
	}
			
     }	
}



#  ---   DB access methods --------


sub openFiles()
{
	open S,'>>'.$tempOutput or print "Error opening file $tempOutput \n
Error: $!\n";
}

sub closeFiles()
{
	close S;
}


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

Date: 5 Aug 2003 03:43:40 -0700
From: sangeetha_b@india.com (sangeetha)
Subject: perl  DBI
Message-Id: <4fde56d3.0308050243.72336b6c@posting.google.com>

Hi Experts,

I'm new to PERL DBI programming i've writen following perl DBI
program, It seems it is nt able to connect to MySQL.

>>>>>>>>>>>>>> Program <<<<<<<<<<<<<<<<<<<

#!perl

use warnings;
use strict;

use DBI;

my $dbh;

$dbh = DBI->connect('dbi:mysql:test','root','pepsi');

unless ($dbh) {
  print "Error opening database: $DBI::errstr\n";
  exit ;
}

my $connected = $dbh->ping;

if ($connected and not int($connected)) {
   print "ping not implemented by '", $dbh->{driver}->{Name},"'.\n";
} else {
   print "Connection is live\n";
}

$dbh->disconnect();

<<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>

Output Error message:

DBI connect('test','root',...) failed: Can't connect to local MySQL
server through socket '/tmp/mysql.sock' (2) at db.pl line 10
Error opening database: Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2)

<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>

Please note i'm able to check my (test) table directly login into
"mysql" by "mysql -u root -p" ... checked "mysqld" is running in
localhost.. MySQL version is "mysql  Ver 11.18 Distrib 3.23.56, for
redhat-linux-gnu (i386)".

Tried: 
Modified the "/etc/my.cnf" file to point the "socket" file to
"/var/lib/mysql//mysql.sock". for the header of "[client] and
[mysqld]" even now it's not working....

Please point where it goes wrong.

Thanks,
Sangeetha.


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

Date: Tue, 5 Aug 2003 08:07:57 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl  DBI
Message-Id: <slrnbivb1d.eqf.tadmc@magna.augustmail.com>

sangeetha <sangeetha_b@india.com> wrote:

> $dbh = DBI->connect('dbi:mysql:test','root','pepsi');
                                       ^^^^^^

Is that the superuser account?

If so, why is it the superuser account?

You should only use root when you *must* use root.

You do not need root privileges to access a database...


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


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

Date: Tue, 05 Aug 2003 15:05:52 +0100
From: Chris <no_thanks@bms.umist.ac.uk>
Subject: Re: perl  DBI
Message-Id: <3f2fc415$1@news.umist.ac.uk>

sangeetha wrote:
> 
> DBI connect('test','root',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at db.pl line 10
> Error opening database: Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
> 

I've got the same problem, but only with one combination of perl and 
mysql. If I use perl 5.6.1 'built for i686-linux' with mysql 3.23.48 I 
get the error, but if use perl 5.6.1 'built for i586-linux' I don't. As 
I have access to both on our network I just use the i586 version.

I don't know what's causing it nor why a simple difference like is 
having an effect, but our overworked sysadmin doesn't have time to look 
into it so I'm making do at the moment. I know this doens't answer your 
question really, but I hope it helps nonetheless :-)

Chris.




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

Date: 3 Aug 2003 20:26:46 -0700
From: srigowrisn@hotmail.com (shree)
Subject: Re: Perl - how to compute totals via hash request
Message-Id: <49b5740e.0308031926.604f8aaa@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3F28150A.7DE322E1@acm.org>...
> shree wrote:
> > 
> > I have a tab delimited log file that contains data of system
> > downtimes. It has 4 fields namely ID, type of downtime (whether
> > planned or unplanned), date and duration of downtime (in secs). I'm
> > asked to compute totals for each month of each type. See input data
> > file provided and mocked output file.
> > 
> > Data File (does not contain header line)
> > ID      Type            Date            DowntimeSecs
> > 1       Planned         01/19/2003      5000
> > 2       Unplanned       01/27/2003      900
> > 3       Unplanned       01/29/2003      300
> > 4       Unplanned       02/12/2003      3690
> > 5       Planned         02/27/2003      1800
> > ..
> > ..
> > 80      Planned         07/12/2003      6000
> > 81      Unplanned       07/15/2003      8400
> > 
> > Hence, the needed output file should be like
> > MonthYear       Planned Unplanned       TotalDownTime
> > Jan2003         5000    1200            6200
> > Feb2003         1800    3690            5490
> > ..
> > ..
> > 
> > I started with the following code
> > 
> > my %count;
> > while(<DATA>) {
> >         chomp;
> >         my ($id, $type, $date, $downtime_secs) = split (/\t/, $_);
> >         $count{$type} += $downtime_secs;
> > }
> > 
> > while (my ($key, $val) = each %count) {
> >  print "$key, $val \n";
> > }
> > which outputs
> > Unplanned, 82000
> > Planned, 90000
> > 
> > How can I modify the above, to give my customer what they wanted. Also
> > if anyone can educate me to how to extract more detailed info as shown
> > below, I would greatly appreciate it. Thank you
> > 
> > MonthYear  Planned Unplanned  Total  NoPlanned  NoUnplanned NoOfTotal
> > Jan2003    5000    1200       6200   1          2           3
> > Feb2003    1800    3690       5490   1          1           2
> 
> This works with the data provided:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> my %count;
> while ( <DATA> ) {
>     chomp;
>     my ( undef, $type, $date, $secs ) = split /\t/;
>     ( my $mon = $date ) =~ s!(\d+)/\d+/(\d+)!$2$1!;
>     $count{ $mon }{ sec }{ $type } += $secs;
>     $count{ $mon }{ cnt }{ $type }++;
>     }
> 
> my @mons = ( undef, qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ) );
> print "            --------- Seconds ---------   ---------- Count ----------\n";
> print "MonthYear   Planned Unplanned     Total   Planned Unplanned     Total\n";
> for my $key ( sort keys %count ) {
>     ( my $mon = $key ) =~ s/(\d{4})(\d\d)/$mons[$2]$1/;
>     printf "%-9s %9d %9d %9d %9d %9d %9d\n", $mon,
>         @{$count{ $key }{ sec }}{ 'Planned', 'Unplanned' },
>         $count{ $key }{ sec }{ Planned } + $count{ $key }{ sec }{ Unplanned },
>         @{$count{ $key }{ cnt }}{ 'Planned', 'Unplanned' },
>         $count{ $key }{ cnt }{ Planned } + $count{ $key }{ cnt }{ Unplanned };
>     }
> 
> __DATA__
> 1       Planned 01/19/2003      5000
> 2       Unplanned       01/27/2003      900
> 3       Unplanned       01/29/2003      300
> 4       Unplanned       02/12/2003      3690
> 5       Planned 02/27/2003      1800
> 80      Planned 07/12/2003      6000
> 81      Unplanned       07/15/2003      8400
> 
> 
> 
> John

Dear John/Tad/Xho,

Thank you. All your solutions worked. I had to modify by adding the
following line
$count{$key}{U} = 0 if (!defined $count{$key}{U});
$count{$key}{P} = 0 if (!defined $count{$key}{P});
only because I was getting use of unintialized values for months when
there was no planned or unplanned downtime. Thanks again and if I can
be of your service, let me know.

Regards,
Shree


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

Date: Mon, 4 Aug 2003 00:07:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl - how to compute totals via hash request
Message-Id: <slrnbirqg5.bo2.tadmc@magna.augustmail.com>

shree <srigowrisn@hotmail.com> wrote:


> Thank you. All your solutions worked. 


You're welcome, but you didn't really need the 100 lines that you quoted.

Please trim your replies and intersperse your comments near the
text that you are commenting on.


> $count{$key}{U} = 0 if (!defined $count{$key}{U});


You can say "if not", or you can say "unless" in Perl:

   $count{$key}{U} = 0 unless defined $count{$key}{U};



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


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

Date: Mon, 4 Aug 2003 11:03:09 +0200
From: "Georg Daniel Vassilopulos" <a@viot.de>
Subject: Perl -> XML
Message-Id: <bgl7ko$gs0$00$1@news.t-online.com>

Hello all!

Is there a all-in-one solution for handling xml documents in perl?
I want to parse xml files, make xql queries. There is no need to genereate
XML.

Should be a simple module, performance is not the problem because there are
only small files,
but it should be a stable module.

Thanks for comments and hints...
Georg
comp.lang.perl.misc_0213@viot.de




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

Date: 4 Aug 2003 13:02:30 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Perl -> XML
Message-Id: <bgllh5$pcgjd$1@ID-24002.news.uni-berlin.de>

Georg Daniel Vassilopulos wrote:

> Is there a all-in-one solution for handling xml documents in perl?
> I want to parse xml files, make xql queries. There is no need to genereate
> XML.

> Should be a simple module, performance is not the problem because there are
> only small files,

perl, XML, simple. googeling for that brings up
XML::Simple which is available on CPAN with
lots of documentation.

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -


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

Date: Mon, 04 Aug 2003 19:43:35 +0200
From: Michel Rodriguez <newsguy@xmltwig.com>
Subject: Re: Perl -> XML
Message-Id: <bgm607$8if$1@news-reader2.wanadoo.fr>

Georg Daniel Vassilopulos wrote:

> Is there a all-in-one solution for handling xml documents in perl?
> I want to parse xml files, make xql queries. There is no need to genereate
> XML.
> 
> Should be a simple module, performance is not the problem because there
> are only small files, but it should be a stable module.

Hi,

Have a look at the Perl-XML FAQ at http://perl-xml.sourceforge.net/faq/, and
be sure to follow the link to Kip Hampton's articles on XML.com

I am not sure whether you really want to use XQL BTW, the most common query
language for XML is XPath, which is very well supported by XML::libXML.

__
Michel Rodriguez
Perl &amp; XML
http://xmltwig.com


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

Date: Sun, 03 Aug 2003 17:35:24 GMT
From: "Ivo" <ivomirb@hotmail.com>
Subject: Perl as embedded scripting language
Message-Id: <wJbXa.11990$Ad4.4779629@news3.news.adelphia.net>

Hi.

I'm working on a Win32 application in C++. It has a set of objects and =
operations you can do with them. Now I want to add scripting to my app. =
I want something small, fast, with a good set of control structures and =
variable types and with its own debugger. I want to be able to easily =
extend the script with my own object types and functions from C++. For =
example if I have a function:
BOOL Process( Object *obj );
I want to call something like "Script.Register(Process,"Process");" and =
after that be able to use the Process function from the script.
 I want the scripting engine to be completely contained within my EXE. I =
don't want to run an external compiler, interpreter, editor or debugger. =
I don't need database support or internet connectivity. Support for =
Win32 GUI would be nice, but not required.

Do you think PERL is the right solution? How easy is it to plug it in an =
existing app? Is it significantly easier than writing a custom script =
engine?

Thanks
Ivo



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

Date: Mon, 4 Aug 2003 01:51:21 +0000 (UTC)
From: Paul Vernaza <vernaza@force.stwing.upenn.edu>
Subject: Re: Perl as embedded scripting language
Message-Id: <slrnbirf0o.s5g.vernaza@force.stwing.upenn.edu>

On Sun, Aug 03 2003 at 17:35 GMT, Ivo <ivomirb@hotmail.com> wrote:
> For example if I have a function:
> BOOL Process( Object *obj );
> I want to call something like "Script.Register(Process,"Process");" and after that be able to use the Process function from the script.

Sounds like Perl would work well in your application.  The XS interface
(man perlxs/perlxstut) allows you to write functions in C or C++ that you can 
then call from Perl, so you could do something like Script.Register(), etc.

>  I want the scripting engine to be completely contained within my EXE. I don't want to run an external compiler, interpreter, editor or debugger. I don't need database support or internet connectivity. Support for Win32 GUI would be nice, but not required.

I don't know much about Perl for Win32, unfortunately, but I don't see why 
you wouldn't be able to statically link Perl into your app.

> Do you think PERL is the right solution? How easy is it to plug it in an existing app? Is it significantly easier than writing a custom script engine?

It's surprisingly easy to embed Perl.  I would recommend reading the 
perlembed man page and copying the example programs there at first.  
Extending/embedding Perl is certainly easier than writing a custom script
engine from scratch (good luck writing an entire language in less than 20
or so lines :).

More recommended reading: the perlapi, perlxs, and perlxstut man pages.
Also, Simon Cozens and Tim Jenness's _Extending and Embedding Perl_.

-- 
Paul Vernaza			     		    University of Pennsylvania
Computer and Telecommunications Engineering	                 Class of 2004


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

Date: 4 Aug 2003 02:03:36 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl as embedded scripting language
Message-Id: <slrnbirfno.cfv.sholden@flexal.cs.usyd.edu.au>

On Mon, 4 Aug 2003 01:51:21 +0000 (UTC),
	Paul Vernaza <vernaza@force.stwing.upenn.edu> wrote:
> On Sun, Aug 03 2003 at 17:35 GMT, Ivo <ivomirb@hotmail.com> wrote:
> 
> It's surprisingly easy to embed Perl.  I would recommend reading the 
> perlembed man page and copying the example programs there at first.  
> Extending/embedding Perl is certainly easier than writing a custom script
> engine from scratch (good luck writing an entire language in less than 20
> or so lines :).
> 
> More recommended reading: the perlapi, perlxs, and perlxstut man pages.
> Also, Simon Cozens and Tim Jenness's _Extending and Embedding Perl_.

This is the wrong place to say such things, but I'm a bit slow...

For C++ projects, python is *really* easy to use for an embedded scripting 
language without having to deal with the 'complicated' stuff. That's
due to the boost.Python C++ library: http://boost.org/libs/python/doc/
The boost library handles both python calling C++ code and C++ code calling
python code.

Of course perl is a nicer language IMHO, but I don't know of such a simple
way to embed it in a C++ application (though I'd love to hear of some).

-- 
Sam Holden



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

Date: 3 Aug 2003 14:48:37 -0700
From: simonf@simonf.com (Simon)
Subject: Perl back-end for Macromedia Petstore example
Message-Id: <3226c4d3.0308031348.3e4945ad@posting.google.com>

Hi,

Out there, there is a cool technology called Flash Remoting that is
used for communications between Flash clients and proprietary servers.
However, I have written Flash::FLAP that rewrites the back-end
functionality in Perl.

I have implemented with FLAP the Macromedia Petstore example, which
originally runs on top of Sun's Blueprints J2EE Petstore. The whole
J2EE functionality is implemented in about 50K of Perl code. :)

Check it out:
http://www.simonf.com/flap/

Simon Ilyushchenko


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

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


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