Re: Hash in file Formats

2015-12-16 Thread Raj Barath
Can you share a simple of JSON file and from that let us know what you want to 
capture.

On Wed, Dec 16, 2015, 3:41 PM perl kamal 
> wrote:
++Subject & Thanks.

On Thu, Dec 17, 2015 at 1:08 AM, perl kamal 
> wrote:
Hi,

I am trying to read a json output file,capture the required information, 
storing them in an array and format the output in a file.
Please review my code and suggest me is there any way to construct the hash 
data structure and use them in the file format.
Instead of this (shift @Data_Sources||''), can we use keys or values.of the 
hash.

Thanks.

use strict;
use Data::Dumper;

my $file = shift || 'input_file.txtt'; # Attachement

my 
($data_source,@Data_Sources,@Stat_Data_Sources,@Min_Data_Sources,@Main_Status,@Test_DB_Con_Status,@Min_Conns,@Max_Conns);


open my $in, '<', "$file" or die $!;
open(FIN_ADV, '>', '/tmp/JsonToTxt.txt') or die "Can't open the file:$!\n";

while (<$in>)
{

#Stats For PayrollServicesDS
  if ( $_ =~ /Stats\s+For\s+(.*)/) {
  $data_source = $1;
push @Min_Data_Sources, $data_source;
 }

push (@Data_Sources,$1) if (/Test\:(.*)/);

 if ( /Test\:(?:.*)/ .. / \"outcome\"/ ) {

  my $status = $1 if ($_ =~ /\"outcome\"\s+\=\>(.*)/) ;
  $status =~ s/[",]//g;
 push @Test_DB_Con_Status, ($status) if defined $status;

 }

 @Stat_Data_Sources = @Data_Sources ;

 next unless ($_ =~ /"max-pool-size" |"min-pool-size" /);

 if ($_ =~ /"max-pool-size"/) {
my $max_value = $1 if ($_ =~ /.*\=\>(.*)/) ;
$max_value =~ s/[",]//g;
push @Max_Conns, $max_value;
  }

if ($_ =~ /"min-pool-size"/) {
my $min_value = $1  if ($_ =~ /.*\=\>(.*)/) ;
$min_value =~ s/[",]//g;

push @Min_Conns, $min_value;
  }

}

 if(my $FORMAT_LINES_LEFT == 10)
  {
  print FIN_ADV_TOP "Data source Statistics\n";
  }



#Fin Adv Report
format FIN_ADV_TOP =
Page:@<<<
$%

.

format FIN_ADV =

===
LIST DATSOURCES
===
@<<<~~
(shift @Data_Sources||'')

===
LIST DATSOURCES Test DatasourceConnection
===
@<~~@<~~
(shift @Stat_Data_Sources),(shift @Test_DB_Con_Status||'')

===
Data source Statistics
===
NAME Min Connection Max Connection
---
@<<~~@|~~@|~~
(shift @Min_Data_Sources||''),(shift @Min_Conns||''),(shift @Max_Conns||'')
.

select(FIN_ADV);
$= = 37;
#$^L = "\n";
write ;



Re: Hash in file Formats

2015-12-16 Thread Raj Barath
Can you share a simple of JSON file and from that let us know what you want to 
capture.

On Wed, Dec 16, 2015, 3:41 PM perl kamal 
> wrote:
++Subject & Thanks.

On Thu, Dec 17, 2015 at 1:08 AM, perl kamal 
> wrote:
Hi,

I am trying to read a json output file,capture the required information, 
storing them in an array and format the output in a file.
Please review my code and suggest me is there any way to construct the hash 
data structure and use them in the file format.
Instead of this (shift @Data_Sources||''), can we use keys or values.of the 
hash.

Thanks.

use strict;
use Data::Dumper;

my $file = shift || 'input_file.txtt'; # Attachement

my 
($data_source,@Data_Sources,@Stat_Data_Sources,@Min_Data_Sources,@Main_Status,@Test_DB_Con_Status,@Min_Conns,@Max_Conns);


open my $in, '<', "$file" or die $!;
open(FIN_ADV, '>', '/tmp/JsonToTxt.txt') or die "Can't open the file:$!\n";

while (<$in>)
{

#Stats For PayrollServicesDS
  if ( $_ =~ /Stats\s+For\s+(.*)/) {
  $data_source = $1;
push @Min_Data_Sources, $data_source;
 }

push (@Data_Sources,$1) if (/Test\:(.*)/);

 if ( /Test\:(?:.*)/ .. / \"outcome\"/ ) {

  my $status = $1 if ($_ =~ /\"outcome\"\s+\=\>(.*)/) ;
  $status =~ s/[",]//g;
 push @Test_DB_Con_Status, ($status) if defined $status;

 }

 @Stat_Data_Sources = @Data_Sources ;

 next unless ($_ =~ /"max-pool-size" |"min-pool-size" /);

 if ($_ =~ /"max-pool-size"/) {
my $max_value = $1 if ($_ =~ /.*\=\>(.*)/) ;
$max_value =~ s/[",]//g;
push @Max_Conns, $max_value;
  }

if ($_ =~ /"min-pool-size"/) {
my $min_value = $1  if ($_ =~ /.*\=\>(.*)/) ;
$min_value =~ s/[",]//g;

push @Min_Conns, $min_value;
  }

}

 if(my $FORMAT_LINES_LEFT == 10)
  {
  print FIN_ADV_TOP "Data source Statistics\n";
  }



#Fin Adv Report
format FIN_ADV_TOP =
Page:@<<<
$%

.

format FIN_ADV =

===
LIST DATSOURCES
===
@<<<~~
(shift @Data_Sources||'')

===
LIST DATSOURCES Test DatasourceConnection
===
@<~~@<~~
(shift @Stat_Data_Sources),(shift @Test_DB_Con_Status||'')

===
Data source Statistics
===
NAME Min Connection Max Connection
---
@<<~~@|~~@|~~
(shift @Min_Data_Sources||''),(shift @Min_Conns||''),(shift @Max_Conns||'')
.

select(FIN_ADV);
$= = 37;
#$^L = "\n";
write ;



Re: Hash in file Formats

2015-12-16 Thread perl kamal
++Subject & Thanks.

On Thu, Dec 17, 2015 at 1:08 AM, perl kamal  wrote:

> Hi,
>
> I am trying to read a json output file,capture the required information,
> storing them in an array and format the output in a file.
> Please review my code and suggest me is there any way to construct the
> hash data structure and use them in the file format.
> Instead of this (shift @Data_Sources||''), can we use keys or values.of
> the hash.
>
> Thanks.
>
> use strict;
> use Data::Dumper;
>
> my $file = shift || 'input_file.txtt'; # Attachement
>
> my
> ($data_source,@Data_Sources,@Stat_Data_Sources,@Min_Data_Sources,@Main_Status,@Test_DB_Con_Status,@Min_Conns,@Max_Conns);
>
>
> open my $in, '<', "$file" or die $!;
> open(FIN_ADV, '>', '/tmp/JsonToTxt.txt') or die "Can't open the file:$!\n";
>
> while (<$in>)
> {
>
> #Stats For PayrollServicesDS
>   if ( $_ =~ /Stats\s+For\s+(.*)/) {
>   $data_source = $1;
> push @Min_Data_Sources, $data_source;
>  }
>
> push (@Data_Sources,$1) if (/Test\:(.*)/);
>
>  if ( /Test\:(?:.*)/ .. / \"outcome\"/ ) {
>
>   my $status = $1 if ($_ =~ /\"outcome\"\s+\=\>(.*)/) ;
>   $status =~ s/[",]//g;
>  push @Test_DB_Con_Status, ($status) if defined $status;
>
>  }
>
>  @Stat_Data_Sources = @Data_Sources ;
>
>  next unless ($_ =~ /"max-pool-size" |"min-pool-size" /);
>
>  if ($_ =~ /"max-pool-size"/) {
> my $max_value = $1 if ($_ =~ /.*\=\>(.*)/) ;
> $max_value =~ s/[",]//g;
> push @Max_Conns, $max_value;
>   }
>
> if ($_ =~ /"min-pool-size"/) {
> my $min_value = $1  if ($_ =~ /.*\=\>(.*)/) ;
> $min_value =~ s/[",]//g;
>
> push @Min_Conns, $min_value;
>   }
>
> }
>
>  if(my $FORMAT_LINES_LEFT == 10)
>   {
>   print FIN_ADV_TOP "Data source Statistics\n";
>   }
>
>
>
> #Fin Adv Report
> format FIN_ADV_TOP =
> Page:@
> <<<
> $%
>
> .
>
> format FIN_ADV =
>
>
> ===
> LIST DATSOURCES
>
> ===
> @<<<~~
>
> (shift @Data_Sources||'')
>
>
> ===
> LIST DATSOURCES Test DatasourceConnection
>
>
> ===
> @<~~@<~~
> (shift @Stat_Data_Sources),(shift @Test_DB_Con_Status||'')
>
>
> ===
> Data source Statistics
>
> ===
> NAME Min Connection Max Connection
>
>
> ---
> @<<~~@|~~@|~~
> (shift @Min_Data_Sources||''),(shift @Min_Conns||''),(shift @Max_Conns||'')
> .
>
> select(FIN_ADV);
> $= = 37;
> #$^L = "\n";
> write ;
>


Re: Hash in file Formats

2015-12-16 Thread perl kamal
Please find the attachment.

On Thu, Dec 17, 2015 at 1:26 AM, Raj Barath  wrote:

> Can you share a simple of JSON file and from that let us know what you
> want to capture.
>
> On Wed, Dec 16, 2015, 3:41 PM perl kamal  wrote:
>
>> ++Subject & Thanks.
>>
>> On Thu, Dec 17, 2015 at 1:08 AM, perl kamal  wrote:
>>
>>> Hi,
>>>
>>> I am trying to read a json output file,capture the required information,
>>> storing them in an array and format the output in a file.
>>> Please review my code and suggest me is there any way to construct the
>>> hash data structure and use them in the file format.
>>> Instead of this (shift @Data_Sources||''), can we use keys or values.of
>>> the hash.
>>>
>>> Thanks.
>>>
>>> use strict;
>>> use Data::Dumper;
>>>
>>> my $file = shift || 'input_file.txtt'; # Attachement
>>>
>>> my
>>> ($data_source,@Data_Sources,@Stat_Data_Sources,@Min_Data_Sources,@Main_Status,@Test_DB_Con_Status,@Min_Conns,@Max_Conns);
>>>
>>>
>>> open my $in, '<', "$file" or die $!;
>>> open(FIN_ADV, '>', '/tmp/JsonToTxt.txt') or die "Can't open the
>>> file:$!\n";
>>>
>>> while (<$in>)
>>> {
>>>
>>> #Stats For PayrollServicesDS
>>>   if ( $_ =~ /Stats\s+For\s+(.*)/) {
>>>   $data_source = $1;
>>> push @Min_Data_Sources, $data_source;
>>>  }
>>>
>>> push (@Data_Sources,$1) if (/Test\:(.*)/);
>>>
>>>  if ( /Test\:(?:.*)/ .. / \"outcome\"/ ) {
>>>
>>>   my $status = $1 if ($_ =~ /\"outcome\"\s+\=\>(.*)/) ;
>>>   $status =~ s/[",]//g;
>>>  push @Test_DB_Con_Status, ($status) if defined $status;
>>>
>>>  }
>>>
>>>  @Stat_Data_Sources = @Data_Sources ;
>>>
>>>  next unless ($_ =~ /"max-pool-size" |"min-pool-size" /);
>>>
>>>  if ($_ =~ /"max-pool-size"/) {
>>> my $max_value = $1 if ($_ =~ /.*\=\>(.*)/) ;
>>> $max_value =~ s/[",]//g;
>>> push @Max_Conns, $max_value;
>>>   }
>>>
>>> if ($_ =~ /"min-pool-size"/) {
>>> my $min_value = $1  if ($_ =~ /.*\=\>(.*)/) ;
>>> $min_value =~ s/[",]//g;
>>>
>>> push @Min_Conns, $min_value;
>>>   }
>>>
>>> }
>>>
>>>  if(my $FORMAT_LINES_LEFT == 10)
>>>   {
>>>   print FIN_ADV_TOP "Data source Statistics\n";
>>>   }
>>>
>>>
>>>
>>> #Fin Adv Report
>>> format FIN_ADV_TOP =
>>>
>>> Page:@<<<
>>>
>>> $%
>>>
>>> .
>>>
>>> format FIN_ADV =
>>>
>>>
>>> ===
>>> LIST DATSOURCES
>>>
>>> ===
>>> @<<<~~
>>>
>>> (shift @Data_Sources||'')
>>>
>>>
>>> ===
>>> LIST DATSOURCES Test DatasourceConnection
>>>
>>>
>>> ===
>>> @<~~@<~~
>>> (shift @Stat_Data_Sources),(shift @Test_DB_Con_Status||'')
>>>
>>>
>>> ===
>>> Data source Statistics
>>>
>>> ===
>>> NAME Min Connection Max Connection
>>>
>>>
>>> ---
>>> @<<~~@|~~@|~~
>>> (shift @Min_Data_Sources||''),(shift @Min_Conns||''),(shift
>>> @Max_Conns||'')
>>> .
>>>
>>> select(FIN_ADV);
>>> $= = 37;
>>> #$^L = "\n";
>>> write ;
>>>
>>
>>
 LIST DATSOURCES 
{
"outcome" => "success",
"result" => {
"data-source" => {
"PayrollTransferUserDataSource" => undefined,
"ReportingDataSource" => undefined,
"ReportingTransferUserDataSource" => undefined,
"PayrollDataSource" => undefined,
"PayrollServicesDS" => undefined
},
"jdbc-driver" => {"oracle" => undefined},
"xa-data-source" => undefined
}
}
 Test Datasoure Connection 
 Test:PayrollDataSource
{
"outcome" => "success",
"result" => [true]
}
 Test:ReportingTransferUserDataSource
{
"outcome" => "success",
"result" => [true]
}
 Test:ReportingDataSource 
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: 
JBAS010447: Connection is not valid",
"rolled-back" => true
}
 Test:PayrollTransferUserDataSource
{
"outcome" => "success",
"result" => [true]
}
Test:PayrollServicesDS 
{
"outcome" => "success",
"result" => [true]
}
 Stats For PayrollServicesDS
{
"outcome" => "success",
"result" => {
"allocation-retry" => undefined,
"idle-timeout-minutes" => 15L,
"jndi-name" => "java:jboss/datasources/PayrollServicesDS",
"jta" => true,
"max-pool-size" => 150,
"min-pool-size" => 15,
"new-connection-sql" => 

Formats for invoices.

2007-06-28 Thread Francisco Valladolid

Hi Folks

I'm doing a single perl script to get data from a database (SQLlite), and
want put some data in a format
The output format is record in a simple  temporary .txt file and send to
lpr.

the format is for a invoice displaying most important data.

I have the next questions.

1.- How can put lines containing products descriptions ?
2.- Ho can justify or align a variable into format ?

if any people can help me, it will be appreciated.

Regards.



--
Francisco Valladolid H.
-- http://bsdguy.net - Perl, [Open-Net] BSD fan. --


Re: Formats for invoices.

2007-06-28 Thread Tom Phoenix

On 6/28/07, Francisco Valladolid [EMAIL PROTECTED] wrote:


1.- How can put lines containing products descriptions ?
2.- Ho can justify or align a variable into format ?


Have you seen the perlform manpage?

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

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Formats for invoices.

2007-06-28 Thread Chas Owens

On 6/28/07, Tom Phoenix [EMAIL PROTECTED] wrote:

On 6/28/07, Francisco Valladolid [EMAIL PROTECTED] wrote:

 1.- How can put lines containing products descriptions ?
 2.- Ho can justify or align a variable into format ?

Have you seen the perlform manpage?

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

snip

Or better yet, the new style forms from Perl 6 backported to Perl 5:

http://search.cpan.org/~dconway/Perl6-Form-0.04/Form.pm

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Formats for invoices.

2007-06-28 Thread Daniel Kasak
On Thu, 2007-06-28 at 17:24 -0700, Tom Phoenix wrote:

 On 6/28/07, Francisco Valladolid [EMAIL PROTECTED] wrote:
 
  1.- How can put lines containing products descriptions ?
  2.- Ho can justify or align a variable into format ?
 
 Have you seen the perlform manpage?
 
 http://perldoc.perl.org/perlform.html
 
 Hope this helps!

Also check out PDF::ReportWriter:
http://entropy.homelinux.org/axis


--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




how can save the expanded tree in different formats.

2006-05-03 Thread onvramakrishnaj1 j
here i am created a tree  using this  Tk::Tree module 
like this pogram 
  #!/pkg/qct/software/perl/bin/perl 
  use Tk; 
use Tk::Tree; 
my $mw = MainWindow-new(-title = 'HList'); 
  my $tree = $mw-Tree-pack; 
foreach (qw/orange 
orange.red 
orange.yellow 
green 
green.blue 
green.yellow 
purple 
purple.red 
purple.blue/) { 
  $treet-add($_, -text = $_); 
  } 


MainLoop; 
  now i am want to provide the menu in main window having  different 
options like 
save as in html format or text format or rtf format , the 
information(in the gui expanded tree ) in the main window. 
which module i have to use and procedure or any books or any sites. 
any  information  may helps alot me . 
  thanks 
Ramakrishna


-
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.

Re: formats

2003-12-06 Thread drieux
On Dec 5, 2003, at 6:39 PM, Jose Malacara wrote:
[..]
write TYPE_1;
that's the sticky bit, where tom is
talking about not writing to a filehandle...
[..]

To expand on tom's comments a bit:
http://www.wetware.com/drieux/pbl/perlTrick/Format/funk_the_form.plx
which generates

Type: type1Gateway: cow Acct ID: lost_id
Start Date: 2003.12.2Start Time: 1400
#---
Type: type2Gateway: pig Acct ID: new
Start Date: 2003.12.2Start Time: 1400
Disconnect Date: 2003.12.3Disconnect Time: 1600
one needs to be thinking in terms of

$~ = 'TYPE_1';
write;
$~ = '';
print #---\n;
HTH.

ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



formats

2003-12-05 Thread Jose Malacara
Is it possible to use more than one format in a script? I am parsing a log file to 
STDOUT and would like to be able to write to two (or more) different formats depending 
on the information found in the log. 

This is what I'm trying to do:

1. open and read logfile
2. if you find some_string print to STDOUT using TYPE_1 format
3. if you find other_string print to STDOUT using TYPE_2 format
5. continue parsing logfile, etc

I can open and parse the logfile, my script breaks whenever I try to call more than 
one type of format. This doesn't seem to work for me, is this even possible?


format TYPE_1 =
Type: @  Gateway: @  Acct ID: @
$record_type,$gateway,$acct_id
Start Date: @  Start Time: @
$start_date,$start_time
.
write TYPE_1;

format TYPE_2 =
Type: @  Gateway: @  Acct ID: @
$record_type,$gateway,$acct_id
Start Date: @  Start Time: @
$start_date,$start_time
Disconnect Date: @  Disconnect Time: @
$disco_date,$disco_time
.
write TYPE_2;


Also, how would I go about keeping the filehandles open as it would be repetively 
writing each format.


Thank you,
Jose


RE: formats

2003-12-05 Thread Tom Kinzer
To just use it for STDOUT, it's pretty straight forward, switching the
special $~ variable as needed.

You're switching FORMATs not filehandles.  There may be a shortcut but this
is how I would do it for this problem:

-Tom Kinzer

_

format TYPE_1 =
Im formated with type1: @  @||
$field1, $field2
.

format TYPE_2 =
IM FORMATTED WITH TYPE2: @  @
$field1, $field2
.

open RECORDS,  YourInput.log or die;

while (RECORDS) {

   ($field1, $field2)  = split;

   if ( m/YourPatternRegExHere/ ) {

   $~ = 'TYPE_1';

   } else {

   $~ = 'TYPE_2';

   }

   write;

}
close RECORDS;

__END__

-Original Message-
From: Jose Malacara [mailto:[EMAIL PROTECTED]
Sent: Friday, December 05, 2003 6:40 PM
To: [EMAIL PROTECTED]
Subject: formats


Is it possible to use more than one format in a script? I am parsing a log
file to STDOUT and would like to be able to write to two (or more) different
formats depending on the information found in the log.

This is what I'm trying to do:

1. open and read logfile
2. if you find some_string print to STDOUT using TYPE_1 format
3. if you find other_string print to STDOUT using TYPE_2 format
5. continue parsing logfile, etc

I can open and parse the logfile, my script breaks whenever I try to call
more than one type of format. This doesn't seem to work for me, is this even
possible?


format TYPE_1 =
Type: @  Gateway: @  Acct ID: @
$record_type,$gateway,$acct_id
Start Date: @  Start Time: @
$start_date,$start_time
.
write TYPE_1;

format TYPE_2 =
Type: @  Gateway: @  Acct ID: @
$record_type,$gateway,$acct_id
Start Date: @  Start Time: @
$start_date,$start_time
Disconnect Date: @  Disconnect Time: @
$disco_date,$disco_time
.
write TYPE_2;


Also, how would I go about keeping the filehandles open as it would be
repetively writing each format.


Thank you,
Jose


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Script chokes on various file formats.

2003-08-16 Thread Ramprasad
Trina Espinoza wrote:
I am starting to write a lot of scripts that require a user to input a file that my script processes for data. Since there are may file formats rtf, txt, microsoft word, etc, my scripts have often choked when users submit the data in various file formats.  I need something to ensure my scripts don't choke.
 

I  already know how to do the open(source,  ./file.txt)  || die stuff stuff stuff:!;

But what I really think I need is the ability to assess the validity of the files (rule out  bad formats) or write something  that makes my code robust enough to handle the most common formats. I'm sure one of these options are doable and I don't really know where to start.

If someone could  give me suggestions or point me to a web page that gives instructions on how to do this that would be much appreciated. 

Thanks!

-T
Incidentally your answer seems to lie in your initial -T

try this
perldoc -f -T
Basically perl can tell you wether your file is a text file or not and 
then you can do whatever with it

Ram





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Script chokes on various file formats.

2003-08-14 Thread Trina Espinoza
I am starting to write a lot of scripts that require a user to input a file that my 
script processes for data. Since there are may file formats rtf, txt, microsoft word, 
etc, my scripts have often choked when users submit the data in various file formats.  
I need something to ensure my scripts don't choke.
 

I  already know how to do the open(source,  ./file.txt)  || die stuff stuff 
stuff:!;

But what I really think I need is the ability to assess the validity of the files 
(rule out  bad formats) or write something  that makes my code robust enough to handle 
the most common formats. I'm sure one of these options are doable and I don't really 
know where to start.

If someone could  give me suggestions or point me to a web page that gives 
instructions on how to do this that would be much appreciated. 


Thanks!

-T

RE: Formats

2002-12-11 Thread Dave Chappell
Please disregard, after a day of hair-pulling and hacking I managed to
figure it out.
 
Dave C. 
 
 -Original Message-
From: Dave Chappell [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, December 10, 2002 11:52 AM
To: [EMAIL PROTECTED]
Subject: Formats



Attached is one of a few (work in progress) scripts that I am creating to
report on security events in a M$ network. The issue I am having is, the
second format, STDBODY is not printing. Since STDBODY can contain many lines
I even tried adding  ~~ to the fieldline as suggested in the Learning Perl
but when I do that I get a Runaway Format error.
 
Another issue I have on the task list, when the script is accessing the
eventlog CPU utilization on the computer running the script is 100%. What
are my options to make the script more efficient?
 
I am still learning perl, if there is anything else that you see, comments
are more than appreciated.
 
Dave C.




Formats

2002-12-10 Thread Dave Chappell
Title: Message



Attached is one of a 
few (work in progress) scripts that I am creating to report on security events 
in a M$ network. The issue I am having is, the second format, STDBODY is not 
printing. SinceSTDBODY can contain many lines I even tried adding ~~ 
to the fieldline as suggested in the Learning Perl but when I do that I get a 
"Runaway Format" error.

Another issue I have 
on the task list, when the script is accessing the eventlog CPU utilization on 
the computer running the script is 100%. What are my options to make the script 
more efficient?

I am still learning 
perl, if there is anything else that you see, comments are more than 
appreciated.

Dave 
C.


dumpevtsec.pl
Description: Binary data
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Converting IE 'Favorites' to other formats

2002-09-13 Thread Ramprasad A Padmanabhan

The Best thing will be to avoid a script
In IE
  Select File - Import  Export in the dialog that appear,select export 
favourites,select Favourites source folder ( select the topmost level, 
to select all).

This creates a html file of your favourites and copy this file as your 
bookmarks.html in mozilla


Phil wrote:
 I've been working on moving from Win2k to Linux and learning Perl 
 at the same time, so I thought I'd kill two birds with one stone and 
 write a Perl program to convert my IE bookmarks to Mozilla format.  
 The meat of the code is at the end - comments and suggestions are 
 more than welcome.
 
 At any rate, the code works and I have my bookmarks in Mozilla.
 However, I'm not completely happy with it.  The output is too 
 closely tied to the input.  I'd like to rewrite it so that the 
 output type could be specified - html, Mozilla, Galeon, etc. 
 I'm not sure where to start, though.  I had thought of reading in
 the favorites and storing it in a tree-type data structure, but
 wasn't sure exactly how to do this or how to write a routine 
 to walk the tree.  Any ideas or pointers to resources?
 
 -Phil
 
 code follows:
 
 open(OUTFILE,$outfile) || 
   die Couldn't open $outfile for writing: $!;
 
 print_header(\*OUTFILE,$rootdir);
  
 # Walk the directory tree and print the links 
 print_favs(\*OUTFILE,$rootdir);
 
 print_footer(\*OUTFILE);
 
 # recursive function to walk the directory tree underneath
 #   the directory passed in as a parameter.  First the directory
 #   is opened, then a list of the files/folders is read into
 #   an array, and then the array is split into a list of files and
 #   a list of directories.  html links are output for the files
 #   and the function is called again for each of the directories.
 #   Stopping condition is when a directory is reached that has only
 #   files, no sub-directories.   
 sub print_favs {
my $fh = $_[0];  # output file handle
my $dir = $_[1]; # current directory
my (@itemlist, @filelist, @dirlist);
 
opendir(CURDIR, $dir) || die Couldn't open $dir: $!\n;
@itemlist = readdir(CURDIR);
chdir($dir) || die Couldn't chdir to $dir: $!\n;
   
if ($dir ne $rootdir) {
print $fh dth3 id=\NC:BookmarksRoot\#$foldernum\\$dir/h3\n;
print $fh dlp\n;
   }
   $foldernum++;

foreach (@itemlist) {
   # print $fh Item: $_\n;
   # Only process non-symbolic links
   if (!(-l $_)) {  
  if ((-d $_)  ($_ !~ /\.\.?/)) {
 @dirlist = (@dirlist, $_);
  }
  elsif ((-f $_)  ($_ =~ /\.url$/i)) {
 @filelist = (@filelist, $_);
  }
   } 
}
foreach (sort @filelist) {
   print $fh dt.getlink($_).\n;
}
foreach (sort @dirlist) {
   print_favs($fh,$_,$foldernum);
}
print $fh /dlp\n;
chdir(..);
 }
   
 # takes the name of a windows internet shortcut file (from 'Favorites')
 #   opens the file and parses out the url it refers to.  The function 
 #   returns an html link with the url as the href and the name of 
 #   the file (without the .url file extension) as the label
 sub getlink {
   my ($file, $line, $url, $name, $link); 
   $file = $_[0];
   open(URLFILE,$file) || die Can't open $file: $!;
   while (defined($line=URLFILE)  ($line !~ /^URL=/)) {
   }
   if (defined($line)) {
  chomp $line; 
  $url = substr($line,4);
  $url =~ s/\cM//;
  #print URL:  $url\n;
  $name = $file; 
  $name =~ s/.+\///;
  $name =~ s/\.url//;
  #print Name:  $name\n; 
  $link = a href=\.$url.\$name/a;
  close(URLFILE);
  return $link;
}
else {
   return ; 
}
 }
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Converting IE 'Favorites' to other formats

2002-09-12 Thread Phil

I've been working on moving from Win2k to Linux and learning Perl 
at the same time, so I thought I'd kill two birds with one stone and 
write a Perl program to convert my IE bookmarks to Mozilla format.  
The meat of the code is at the end - comments and suggestions are 
more than welcome.

At any rate, the code works and I have my bookmarks in Mozilla.
However, I'm not completely happy with it.  The output is too 
closely tied to the input.  I'd like to rewrite it so that the 
output type could be specified - html, Mozilla, Galeon, etc. 
I'm not sure where to start, though.  I had thought of reading in
the favorites and storing it in a tree-type data structure, but
wasn't sure exactly how to do this or how to write a routine 
to walk the tree.  Any ideas or pointers to resources?

-Phil

code follows:

open(OUTFILE,$outfile) || 
die Couldn't open $outfile for writing: $!;

print_header(\*OUTFILE,$rootdir);
 
# Walk the directory tree and print the links 
print_favs(\*OUTFILE,$rootdir);

print_footer(\*OUTFILE);

# recursive function to walk the directory tree underneath
#   the directory passed in as a parameter.  First the directory
#   is opened, then a list of the files/folders is read into
#   an array, and then the array is split into a list of files and
#   a list of directories.  html links are output for the files
#   and the function is called again for each of the directories.
#   Stopping condition is when a directory is reached that has only
#   files, no sub-directories.   
sub print_favs {
   my $fh = $_[0];  # output file handle
   my $dir = $_[1]; # current directory
   my (@itemlist, @filelist, @dirlist);

   opendir(CURDIR, $dir) || die Couldn't open $dir: $!\n;
   @itemlist = readdir(CURDIR);
   chdir($dir) || die Couldn't chdir to $dir: $!\n;
  
   if ($dir ne $rootdir) {
   print $fh dth3 id=\NC:BookmarksRoot\#$foldernum\\$dir/h3\n;
   print $fh dlp\n;
}
$foldernum++;
   
   foreach (@itemlist) {
  # print $fh Item: $_\n;
  # Only process non-symbolic links
  if (!(-l $_)) {  
 if ((-d $_)  ($_ !~ /\.\.?/)) {
@dirlist = (@dirlist, $_);
 }
 elsif ((-f $_)  ($_ =~ /\.url$/i)) {
@filelist = (@filelist, $_);
 }
  } 
   }
   foreach (sort @filelist) {
  print $fh dt.getlink($_).\n;
   }
   foreach (sort @dirlist) {
  print_favs($fh,$_,$foldernum);
   }
   print $fh /dlp\n;
   chdir(..);
}
  
# takes the name of a windows internet shortcut file (from 'Favorites')
#   opens the file and parses out the url it refers to.  The function 
#   returns an html link with the url as the href and the name of 
#   the file (without the .url file extension) as the label
sub getlink {
  my ($file, $line, $url, $name, $link); 
  $file = $_[0];
  open(URLFILE,$file) || die Can't open $file: $!;
  while (defined($line=URLFILE)  ($line !~ /^URL=/)) {
  }
  if (defined($line)) {
 chomp $line; 
 $url = substr($line,4);
 $url =~ s/\cM//;
 #print URL:  $url\n;
 $name = $file; 
 $name =~ s/.+\///;
 $name =~ s/\.url//;
 #print Name:  $name\n; 
 $link = a href=\.$url.\$name/a;
 close(URLFILE);
 return $link;
   }
   else {
  return ; 
   }
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Time and date formats

2002-03-01 Thread Troy May

What do the letters after the %02 mean?  I know about %02d, but I came
across a few scripts with %02u in it.  I've never seen that, what does it
mean?  What's the difference between the d and the u?  And what ELSE can
you possibly use there?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Time and date formats

2002-03-01 Thread Timothy Johnson

 
Check the documentation on sprintf().  I don't have perl with me, but I
think perldoc -f sprintf will find it, otherwise you can look through the
perlfunc section of the docs for sprintf.  Offhand I'd guess that %02u
refers to an unsigned integer in decimal format?

-Original Message-
From: Troy May
To: Perl Beginners
Sent: 3/1/02 5:50 PM
Subject: Time and date formats

What do the letters after the %02 mean?  I know about %02d, but I
came
across a few scripts with %02u in it.  I've never seen that, what does
it
mean?  What's the difference between the d and the u?  And what ELSE
can
you possibly use there?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Time and date formats

2002-03-01 Thread Brett W. McCoy

On Fri, 1 Mar 2002, Troy May wrote:

 What do the letters after the %02 mean?  I know about %02d, but I came
 across a few scripts with %02u in it.  I've never seen that, what does it
 mean?  What's the difference between the d and the u?  And what ELSE can
 you possibly use there?

I can only assume you mean in a sprintf format string (you should specify
such things so people know what you are talking about).  The 'u' means
'unsigned integer'.

Take a look at the sprintf documentation:

perldoc -f sprintf

-- Brett
  http://www.chapelperilous.net/

Don't read everything you believe.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Formats

2002-02-01 Thread ABhagwandin

Why does the following not work for me?

format NAME =
TEST

@
$test
..
 
$test = asdfjkl;;
 
select(NAME);
write();
 
__END__

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




FW: Formats

2002-02-01 Thread ABhagwandin



-Original Message-
From: Anthony Bhagwandin 
Sent: Friday, February 01, 2002 1:11 PM
To: [EMAIL PROTECTED]
Subject: Formats


Why does the following not work for me?

format NAME =
TEST

@
$test

 
$test = asdfjkl;;
 
select(NAME);
write();
 
__END__

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Formats

2002-02-01 Thread Jeff 'japhy' Pinyan

On Feb 1, [EMAIL PROTECTED] said:

Why does the following not work for me?

format NAME =
TEST

@
$test
..
 
$test = asdfjkl;;
 
select(NAME);
write();

That tries writing to the filehandle NAME, too.  Instead of select(NAME),
do:

  $~ = NAME;

That will set STDOUT's default format name to NAME.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Formats, cont'd

2002-02-01 Thread ABhagwandin

I have two arrays, @array_a and @array_b, that contain info I want
formatted. I would like to have the output look something like:

dataset A   dataset B
--
a1  b1
a2  b2
a3  b3

a(n)b(n)

where a1 is the first element of @array_a, b1 is the first element of
@array_b. Every time I try something, I get a runaway format, so nothing
gets printed to screen. Any ideas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Formats, cont'd

2002-02-01 Thread Wagner-David

Maybe one of the guru's can help us, but here is one way:

#!perl -w

use strict;

my @a1 = ();# leaving out $a1[1]  so undefined and can use the check of undefined 
in loop 
$a1[0] = 1;
$a1[2] = 3;
$a1[3] = 4;
$a1[4] = 5;
$a1[5] = 6;

my @b1 = (2,3,4,5,6,7);
my $Mya1;
my $Myb1;
my $MyId;

format HEADER =
Id  Test1Test2
---  
..

format NAME =
@ @ @
$MyId, $Mya1 , $Myb1
..

$~ = HEADER;
write();
$~ = NAME;

#select(STDOUT);
my $MyMax = scalar(@a1);
$MyMax = scalar(@b1) if ( scalar(@b1)  $MyMax);
for($MyId=0;$MyId$MyMax;$MyId++) {
   $Mya1 = 'n';
   $Myb1 = 'n';
   $Mya1 = $a1[$MyId] if ( defined $a1[$MyId] and $a1[$MyId] gt '' );
   $Myb1 = $b1[$MyId] if ( defined $b1[$MyId] and $b1[$MyId] gt '' );
   write;
 } 

__END__

Output:
Id  Test1Test2
---  
  0 12
  1 n3
  2 34
  3 45
  4 56
  5 67

Wags ;)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 01, 2002 10:46
To: [EMAIL PROTECTED]
Subject: Formats, cont'd


I have two arrays, @array_a and @array_b, that contain info I want
formatted. I would like to have the output look something like:

dataset A   dataset B
--
a1  b1
a2  b2
a3  b3
.
a(n)b(n)

where a1 is the first element of @array_a, b1 is the first element of
@array_b. Every time I try something, I get a runaway format, so nothing
gets printed to screen. Any ideas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




writing formats

2002-01-29 Thread Thunem, Tom

can anyone tell me how to toggle between 2 different formats writing to the
same output filehandle?  i am not having luck with coding the select and
write statements.

thanks

Tom Thunem
Sr. Systems Specialist,
Global E-Business Infrastructure, Americas
Avnet, Inc.
[EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: writing formats

2002-01-29 Thread Jeff 'japhy' Pinyan

On Jan 29, Thunem, Tom said:

can anyone tell me how to toggle between 2 different formats writing to the
same output filehandle?  i am not having luck with coding the select and
write statements.

By default, the format for any given filehandle has the same name as the
filehandle itself.  To change that, select() the filehandle to work with,
and set $~ to the format name.

  format FOO =
  Name: @   Age: @##
$name,   $age
  .

  format BAR =
  Occupation: @   Years Exp.: @#
  $occup,   $exp
  .

  select RECORD;
  $~ = FOO;
  write;  # writes format FOO to RECORD
  $~ = BAR;
  write;  # writes format BAR to record

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: writing formats

2002-01-29 Thread William.Ampeh


The trick is to make sure that your output file has the same name as your
main format routine.

So in my case I have:

select (STDOUT);

and

format STDOUT =

The STDOUT_TOP  is automatically selected at the beginning of each page.


Maybe this will help (that is if it is not too late)

The output looks like this:

  Annual Report on Car Sale  January-2002
Page: 1

__

  ColumnColumn  Column
Column
   One   Two Three
Four

__
   Blue_car_col_1 Blue_car_col_2 Blue_car_col_3
Blue_car_col_4
   Red_car_col_1   Red_car_col_2 Red_car_col_3
Red_car_col_4
   Blue_car_col_1 Blue_car_col_2 Blue_car_col_3
Blue_car_col_4
   Red_car_col_1   Red_car_col_2 Red_car_col_3
Red_car_col_4
   Blue_car_col_1 Blue_car_col_2 Blue_car_col_3
Blue_car_col_4

   Red_car_col_1   Red_car_col_2 Red_car_col_3
Red_car_col_4
   Blue_car_col_1 Blue_car_col_2 Blue_car_col_3
Blue_car_col_4
   Red_car_col_1   Red_car_col_2 Red_car_col_3
Red_car_col_4
   Blue_car_col_1 Blue_car_col_2 Blue_car_col_3
Blue_car_col_4


__



MAIN PROGRAM.  Kind of raw.


-
#!/opt/local/bin/perl

$CUR_TIME=`date +%B-%Y`;
$TITLE=Annual Report on Car Sales;

select (STDOUT);

$~ = STDOUT;
for ($i = 1; $i 10; $i++) {

   $color = Red;
   if ( $i % 2 ) { $color = Blue};

   $col1 = ${color}_car_col_1;
   $col2 = ${color}_car_col_2;
   $col3 = ${color}_car_col_3;
   $col4 = ${color}_car_col_4;

   write STDOUT;

   if ( $i % 5 == 0 ) {
  $~ = STDOUT_BLANK;  write STDOUT_BLANK;
  $~ = STDOUT;
   }
}

$~ = STDOUT_BOTTOM; write;

#---  OUTPUT FORMAT BEGINS HERE ---

format STDOUT =
   @@ @
@|
$col1, $col2, $col3, $col4

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Substitution formats

2002-01-20 Thread Mo Holkar / UKG

At 07:45 20/01/02, Troy wrote:
Hello,

I only knew of one way to do them:  s///

But japhy once answered me with this format:  s{}{}

Another guy said you can use exclamation points?  I'm assuming: s!!!

I've tried some other formats with brackets, parenthesis, etc.  Nothing else
works.

What other formats will work?


Hi there,

You can use any (non-alphanumeric, non-whitespace) character you like for 
this operator, as long as you use the same one throughout the expression. 
And it can either be repeated three times, like s/a/b/ or s#a#b#, or in two 
pairs, like s{a}{b} or s[a][b]. (Actually I think that if you use pairs, 
the two pairs can be different from each other, like s[a]{b}. But that 
would most likely be unnecessarily confusing ;-)

best,

Mo



Mo Holkar
Undying King Games
[EMAIL PROTECTED]
Free games! at http://www.ukg.co.uk


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Substitution formats

2002-01-20 Thread Gary Hawkins

I'm a big fan of s###.  Easy for me to read.

/g

 -Original Message-
 From: Troy May [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, January 19, 2002 11:45 PM
 To: Perl Beginners
 Subject: Substitution formats
 
 
 Hello,
 
 I only knew of one way to do them:  s///
 
 But japhy once answered me with this format:  s{}{}
 
 Another guy said you can use exclamation points?  I'm assuming: s!!!
 
 I've tried some other formats with brackets, parenthesis, etc.  Nothing else
 works.
 
 What other formats will work?
 
 Thanks!
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Substitution formats

2002-01-19 Thread Troy May

Hello,

I only knew of one way to do them:  s///

But japhy once answered me with this format:  s{}{}

Another guy said you can use exclamation points?  I'm assuming: s!!!

I've tried some other formats with brackets, parenthesis, etc.  Nothing else
works.

What other formats will work?

Thanks!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Substitution formats

2002-01-19 Thread Troy May

Hello,

I only knew of one way to do them:  s///

But japhy once answered me with this format:  s{}{}

Another guy said you can use exclamation points?  I'm assuming: s!!!

I've tried some other formats with brackets, parenthesis, etc.  Nothing else
works.

What other formats will work?

Thanks!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Displaying text formats in a text widget...

2001-06-12 Thread Jeff 'japhy' Pinyan

On Jun 12, Brennan, Corey said:

I am trying to convert a script to Perl/Tk and I am having trouble.  I have
some formats defined 

I've no clue how you'd get formats to write() to a Tk widget... you'd have
to use formline() and the $^A variable, methinks.

But have no fear -- I'm in the process of writing a format-to-sprintf
module that will allow you to convert your use of formats (which are
becoming more and more ancient) to more understandable (?) and
maintainable (!) sprintf() calls.

format  DATA_OUT_TOP = 
col1 col2 col3
---
.

This would look like:

  sprintf  END;
  col1 col2 col3
  ---
  END

format  DATA_OUT = 
@|@|@||
$text  $text1   $text2
.

This would look like

  sprintf  END,
  %6.6s%6.6s%7.7s
  END
center($text,6), center($text1,6), center($text2,7);

Like so.  The center() call is only needed because there is no
sprintf() means for centering, but there are for left and right aligning.

I might even make it so that you can make the sprintf() which is called
internally, not by the user, to know centering, via something like

  %|6.6s

Default string alignment is to the right, and to get left-alignment, you'd
use -6 (or whatever number).

More news as the module develops.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **