Re: How to append to a file in a Archive::Zip object ?

2016-10-24 Thread Vincent Lequertier
On 10/22/2016 06:56 PM, Eric de Hont wrote:
> Op 21-10-16 om 14:13 schreef Vincent Lequertier:
>> This code creates a zip file which contains several files, all named
>> 'test'. The thing I'm trying to achieve is to have all the output of
>> commands being appended to a 'test' file, into the zip.
>>
>> How can I do this properly ? I mean without having to create a temp file
>> with a filehandle with all the output and adding the file to the zip
>> after the for loop.
> A zip-file is no compressed filesystem, so I think there is no way to do
> what you want properly.
> 
> You could do something like this, but in the else block you will have
> all of your data temporarily uncompressed in memory:
> 
> if (! $zip->memberNamed( 'test' )) {
> $zip->addString($config, 'test', COMPRESSION_DEFLATED);
> }  
> else {
> $zip->contents( 'test', $zip->contents( 'test' ) . $config );
> }  
> 
> If it's too much data to fit in memory you have to go with the temp file
> option.
> 
> Just a thought though: perhaps a zip archive to compress just one file
> is a bit overkill.
> 
> Maybe IO::Compress::Gzip, which let's you compress strings in this way:
> 
> gzip \$input \$output
> 
> is better suited, or could at least be used in stead of the temp file.
> 
> Greetings,
> Eric de Hont

Your approach works well, thanks. I'm ziping a lot of files by the way
(but I have only one file that needs to be a concatenation of multiple
strings in the loop). I've just shown this tiny example to highlight
what the problem was.

Thank you again

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How to append to a file in a Archive::Zip object ?

2016-10-21 Thread Vincent Lequertier
Hello,

I'm a bit stuck with Archive::Zip. I'm trying to find a clean way to
append to a file inside a Archive::Zip object. See the code below:

my $zip = Archive::Zip->new();
for my $master(@{$json}) {
$config = qx /some command depending on $master/;
$zip->addString($config, 'test', COMPRESSION_DEFLATED);
}

...

die 'write error' if ($zip->writeToFileNamed('test.zip') != AZ_OK);


This code creates a zip file which contains several files, all named
'test'. The thing I'm trying to achieve is to have all the output of
commands being appended to a 'test' file, into the zip.

How can I do this properly ? I mean without having to create a temp file
with a filehandle with all the output and adding the file to the zip
after the for loop.

Any help would be appreciated.

Thanks

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Problems displaying Perl structures

2016-02-22 Thread Vincent Lequertier
Le 18/02/2016 08:24, $Bill a écrit :
> On 2/17/2016 03:15, Vincent Lequertier wrote:
>>
> 
> I'd get rid of the '$'s in front of '$group1' etc to avoid the '$ip =~
> s/^\$//;' below.
> 
>> How can I have the following output?
>>
>> ,"10.100.29.0/24"
>> ,10.100.27.52
>> ,10.100.27.53
>> ,10.100.27.54
>> ,10.100.27.55
>> ,10.100.27.56
>> ,10.100.27.57
> 
> My version:
> 
> my %vars = (
>   'group1' => '10.100.27.52',
>   'group2' => '10.100.27.53',
>   'group3' => '10.100.27.54',
>   'group4' => '10.100.27.55',
>   'group5' => '10.100.27.56',
>   'group6' => '10.100.27.57',
> );
> 
> my @tables = (
>   {
> 'ips' => [
>   '"10.100.29.0/24"',
> ],
> 'tablename' => '',
>   },
>   {
> 'ips' => [
>   '$group1',
>   '$group2',
>   '$group3',
> ],
> 'tablename' => '',
>   },
>   {
> 'ips' => [
>   '$group4',
>   '$group5',
>   '$group6',
> ],
> 'tablename' => '',
>   }
> );
> # print (Data::Dumper->Dump([\%vars, \@tables], [qw(%vars @tables)]));
> 
> # loop over elements of @table
> for (my $ii = 0; $ii < @tables; ++$ii) {
> # do for each ip in element
> foreach my $ip (@{$tables[$ii]{'ips'}}) {# critical code here
> if ($ip =~ /^\$group/i) { $ip =~ s/^\$//; $ip = $vars{$ip}; }
> printf "%s,%s\n", $tables[$ii]{'tablename'}, $ip;
> }
> }
> 
> __END__
> 

Your code won't work on my real world environment because $ip not allays
matchs '$groups'. It could be any word btw. So I ended up with this :

print($vars{$table->{ips}[$_]}
   ? $vars{$table->{ips}[$_]}
   : $table->{ips}[0]);


Thank you for your feedbacks!

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Problems displaying Perl structures

2016-02-17 Thread Vincent Lequertier
Didn't know about 2) and 5) thanks. Looping over the values makes sense
as well.

Regards,

Le 17/02/2016 15:31, Shlomi Fish a écrit :
> Hi Vincent,
> 
> some comments on your code:
> 
> On Wed, 17 Feb 2016 14:24:28 +0100
> Vincent Lequertier <s...@riseup.net> wrote:
> 
>> Thank you for your answer, however I think you have misunderstood my
>> problem. I needed to loop over the $groupX in @table while interpolating
>> the ip addresses from %vars and displaying the table name.
>> But I finally got it to work :-)
>>
>> I was looking for this kind of lines :
>>
>> for my $table (@tables) {
>> for (0 .. (scalar (@{ $table->{ips} })) - 1) {
> 
> 1. It is a good idea to avoid looping using $_ which can be clobbered very
> easily - use a lexical my variable instead.
> 
> 2. scalar(@arr)-1 is more idiomatically written as $#{arr}.
> 
> 3. You're using $table->{ips} more than one time so you should assign it to a
> variable.
> 
> 4. Looping over the values of the array will be better than looping over its
> indices - at least in this case.
> 
> 5. If your version of perl is recent enough, then you can use keys(@arr)
> instead of 0 .. $#arr.
> 
> ---
> 
> For more information, see:
> 
> http://perl-begin.org/tutorials/bad-elements/
> 
> Regards,
> 
>   Shlomi
> 
> 
>> print $table->{tablename} . ',';
>> print $vars{$table->{ips}[$_]};
>> }
>> }
>>
>>
>> Thank you anyway
> 

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Problems displaying Perl structures

2016-02-17 Thread Vincent Lequertier
Thank you for your answer, however I think you have misunderstood my
problem. I needed to loop over the $groupX in @table while interpolating
the ip addresses from %vars and displaying the table name.
But I finally got it to work :-)

I was looking for this kind of lines :

for my $table (@tables) {
for (0 .. (scalar (@{ $table->{ips} })) - 1) {
print $table->{tablename} . ',';
print $vars{$table->{ips}[$_]};
}
}


Thank you anyway



Le 17/02/2016 12:54, Rui Fernandes a écrit :
> Hi,
> 
> Try this (read comments please...)
> 
> #!/usr/bin/perl
> 
> print "Content-type: text/html\n\n";
> 
> 
> my $VAR1 = {
>   'group1' => '10.100.27.52',
>   'group2' => '10.100.27.53',
>   'group3' => '10.100.27.54',
>   'group4' => '10.100.27.55',
>   'group5' => '10.100.27.56',
>   'group6' => '10.100.27.57' #Last element has no comma...
> 
> };
>
> $count = 0;
> 
> while (($key, $value) = each %$VAR1) { # $key has group5 for intance,
> and $value its value.
> 
>$count += 1;
> 
>$output = "\<table$count\>\,$value\n";
>print $output;
> 
> }
> 
> exit;
> 
> Cheers,
> 
> Miguel
> 
> Este e-mail foi enviado a partir de um computador sem vírus protegido
> pela Avast.
> www.avast.com <https://www.avast.com/sig-email>
> 
> 
> On Wed, Feb 17, 2016 at 11:15 AM, Vincent Lequertier <s...@riseup.net
> <mailto:s...@riseup.net>> wrote:
> 
> Hello!
> 
> 
> I have the following data(sanitized) :
> 
> print Dumper \%vars
> 
> $VAR1 = {
>   'group1' => '10.100.27.52',
>   'group2' => '10.100.27.53',
>   'group3' => '10.100.27.54',
>   'group4' => '10.100.27.55',
>   'group5' => '10.100.27.56',
>   'group6' => '10.100.27.57',
> 
> };
> 
> 
> print Dumper \@tables
> 
> $VAR1 = [
>   {
> 'tablename' => '',
> 'ips' => [
>'"10.100.29.0/24 <http://10.100.29.0/24>"'
>  ]
>   },
>   {
> 'ips' => [
>'$group1',
>'$group2',
>'$group3'
>  ],
> 'tablename' => ''
>   },
>   {
> 'tablename' => '',
> 'ips' => [
>'$group4',
>'$group5'
>'$group6'
>  ]
>   }
> ];
> 
> 
> How can I have the following output?
> 
> ,"10.100.29.0/24 <http://10.100.29.0/24>"
> ,10.100.27.52
> ,10.100.27.53
> ,10.100.27.54
> ,10.100.27.55
> ,10.100.27.56
> ,10.100.27.57
> 
> Here is what I've tried:
> 
> for my $table (@tables) {
> foreach my $entry ($table->{ips}) {
> print $table->{tablename};
> print $vars{$entry};
> }
> }
> 
> My problem is that I don't understand what I should use to loop over
> 'ips' and what to put inside $vars{}. Is my data structure appropriate
> to my needs?
> 
> Let me know If you need more information, if you need the full code, etc
> 
> Thanks in advance
> 
> 
> --
> Vincent Lequertier
> skysymbol.github.io <http://skysymbol.github.io>
> 
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> <mailto:beginners-unsubscr...@perl.org>
> For additional commands, e-mail: beginners-h...@perl.org
> <mailto:beginners-h...@perl.org>
> http://learn.perl.org/
> 
> 
> 
> 
> 
> -- 
> /
> Rui Miguel Fernandes
> /
> /Porto - Portugal/
> 
> /Website:
> Cosmos - Portal Interactivo de Astronomia / Interactive Gate of Astronomy
> http://www.cosmos.pt/

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Problems displaying Perl structures

2016-02-17 Thread Vincent Lequertier
Hello!


I have the following data(sanitized) :

print Dumper \%vars

$VAR1 = {
  'group1' => '10.100.27.52',
  'group2' => '10.100.27.53',
  'group3' => '10.100.27.54',
  'group4' => '10.100.27.55',
  'group5' => '10.100.27.56',
  'group6' => '10.100.27.57',

};


print Dumper \@tables

$VAR1 = [
  {
'tablename' => '',
'ips' => [
   '"10.100.29.0/24"'
 ]
  },
  {
'ips' => [
   '$group1',
   '$group2',
   '$group3'
 ],
'tablename' => ''
  },
  {
'tablename' => '',
'ips' => [
   '$group4',
   '$group5'
   '$group6'
 ]
  }
];


How can I have the following output?

,"10.100.29.0/24"
,10.100.27.52
,10.100.27.53
,10.100.27.54
,10.100.27.55
,10.100.27.56
,10.100.27.57

Here is what I've tried:

for my $table (@tables) {
foreach my $entry ($table->{ips}) {
print $table->{tablename};
print $vars{$entry};
}
}

My problem is that I don't understand what I should use to loop over
'ips' and what to put inside $vars{}. Is my data structure appropriate
to my needs?

Let me know If you need more information, if you need the full code, etc

Thanks in advance


-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Display a hash in the order of an array

2015-07-21 Thread Vincent Lequertier

Le 2015-07-20 16:49, Charles DeRykus a écrit :
On Mon, Jul 20, 2015 at 6:19 AM, Vincent Lequertier s...@riseup.net 
wrote:
Thank you for the help, Charles! Unfortunately, I'm not able to figure 
out
how to access the element of %ordered, despite some diggings in the 
perldoc

(http://perldoc.perl.org/perldsc.html).
I can print a single element with print
$ordered{'xxx.xxx.xxx.xxx'}[0]{'[15/Jul/2015:10:30:03 
+0200]'}{action};


But I don't find how to get the dates e.g. '[15/Jul/2015:10:30:03 
+0200]'


Here is what I've tried:

tie( my %ordered, 'Tie::IxHash', map { ( $_,[ ] ) }   @ip );

while ( my($key,$value) = each %hash ) {
push @{$ordered{$value-{ip}}}, {$key, $value};
}
#print Dumper \%ordered;
my $i = 1;
for my $key (keys %ordered) {
print ip number $i : $key\n;
for my $entry (@{$ordered{$key}}) {
print $entry . \n;
}
++$i;
}



Depending on output preference and level of detail, one possibility:

...
   for  foreach my $entry ( @{$ordered{$ip}} ) {
while ( my($date, $data) = each %{$entry} ) {
  say join(  ,$date:, $data-{ip}, $data-{action} );
}
   }

--
Charles DeRykus



Thanks a lot, now I get what I need. Thanks to those who helped me as 
well. Great community


--
Vincent Lequertier
vincentlequertier.tk

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
Thank you, I thought about transforming my hash like your function 
transform_date_logs_to_ip_logs does but didn't found the way. I'm now 
trying to understand exactly how that works :-)



--
Vincent Lequertier
vincentlequertier.tk

Le 2015-07-17 16:40, Brandon McCaig a écrit :

Vincent:

On Fri, Jul 17, 2015 at 9:11 AM, Vincent Lequertier s...@riseup.net 
wrote:

Hi,


Hello,


I have the following structure :

$hash{$date} = {
'ip' = $ip,
'action'   = $action,
};

witch produce data like :

$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
  'ip' = 'xxx.xxx.xxx.xxx',
  'action' = 'GET xxx'
};

and an array of ip addresses, say @ip

My question is how can I display the content of %hash in the
order of @ip, assuming %hash has the same length as @ip ?


Unfortunately this data structure isn't ideal for doing this.
You'll have to search the hash structure for the matching IP
addresses.

You may wish to transform the data structure first (or simply
store it differently in the first place if this is all you need
it for).

If the hash keys were IP addresses then you could simply loop
over the elements of @ip (some would argue arrays and hashes
should have plural names) and use the current IP address to
address the current hash element from '%hash' (note: hash is
usually a poor name for a variable).

use strict;
use warnings;

use Data::Dumper;

sub cmp_ip_addresses {
my @parts = map { split /\./, $_ } $a, $b;

for my $i (0..4) {
my $result = $parts[$i] = $parts[$i + 4];

if ($result) {
return $result;
}
}

return 0;
}

# The resulting structure will be inverted so the keys are IPs
# and the values are references to hashes containing a date and
# action (you could go further and store actions by date, or
# dates by action; depends how you want the data shaped).

sub transform_date_logs_to_ip_logs {
my ($logs) = @_;
my %logs;

while(my ($date, $entry) = each(%{$logs})) {
my ($ip, $action) = @{$entry}{qw/ip action/};

push @{$logs{$ip}}, { date = $date, action = $action};
}

return \%logs;
}

my @ip_addresses = qw(
192.168.200.220
1.0.0.127
192.168.90.221
);

my %date_logs = (
'15/Jul/2015:10:30:01 +0200' = {
ip = '1.0.0.127',
action = 'GET http://1.0.0.127/foo',
},
'15/Jul/2015:10:30:04 +0200' = {
ip = '192.168.90.221',
action =  'GET http://192.168.90.221/bar',
},
'15/Jul/2015:10:30:05 +0200' = {
ip = '192.168.200.220',
action = 'GET http://192.168.200.220/baz',
},
'15/Jul/2015:10:30:03 +0200' = {
ip = '1.0.0.127',
action = 'GET http://1.0.0.127/foo/bar',
},
);

my $ip_logs = transform_date_logs_to_ip_logs(\%date_logs);

for my $ip (sort { cmp_ip_addresses() } @ip_addresses) {
my $entries = $ip_logs-{$ip};

for my $entry (@{$entries}) {
my ($date, $action) = @{$entry}{qw/date action/};

print Date: $date, IP Address: $ip, Action: $action\n;
}
}

__END__


Regards,


--
Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org
Castopulence Software https://www.castopulence.org/
Blog http://www.bambams.ca/
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
Thank you for the help, but this does not work. We needa pass the ip 
addresses to the sorting function, because actually the keys of the hash 
are the dates


$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
   'ip' = 'xxx.xxx.xxx.xxx',
   'action' = 'GET xxx'
 };

The workaround I found is to loop over the hash, push an array with the 
ip addresses, and sort them, like this :


sub sort_by_ip {
my @ip;
for my $key (keys %hash) {
push @ip, $hash{$key}{ip};
}
my @ip_sorted = map  { $_-[0] }
sort { $a-[1] = $b-[1] }
map  { [$_, int sprintf(%03.f%03.f%03.f%03.f, 
split(/\./, $_))] } @ip;

}

So I'm looking for a way to iterate through the hash in the order of my 
array.


Regards
--
Vincent Lequertier
vincentlequertier.tk

Le 2015-07-17 15:50, Shawn H Corey a écrit :

On Fri, 17 Jul 2015 15:11:13 +0200
Vincent Lequertier s...@riseup.net wrote:


Hi,

I have the following structure :

$hash{$date} = {
 'ip' = $ip,
 'action'   = $action,
 };

witch produce data like :

$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
   'ip' = 'xxx.xxx.xxx.xxx',
   'action' = 'GET xxx'
 };

and an array of ip addresses, say @ip

My question is how can I display the content of %hash in the order of
@ip, assuming %hash has the same length as @ip ?

Thank you



UNTESTED:

sub ip_cmp {
  my @ip_a = split /\./, $a;
  my @ip_b = split /\./, $b;

  for my $i ( 0 .. 3 ){
my $cmp = ( $ip_a[$i] || 0 ) = ( $ip_b[$1] || 0 );
return $cmp if $cmp != 0;
 }
  return 0;
}

for my $hash_ref ( sort ip_cmp keys %hash ){
# display $hash_ref-{$date}
}


--
Don't stop where the ink does.
Shawn


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
Thank you for the help, Charles! Unfortunately, I'm not able to figure 
out how to access the element of %ordered, despite some diggings in the 
perldoc (http://perldoc.perl.org/perldsc.html).
I can print a single element with print 
$ordered{'xxx.xxx.xxx.xxx'}[0]{'[15/Jul/2015:10:30:03 +0200]'}{action};


But I don't find how to get the dates e.g. '[15/Jul/2015:10:30:03 
+0200]'


Here is what I've tried:

tie( my %ordered, 'Tie::IxHash', map { ( $_,[ ] ) }   @ip );

while ( my($key,$value) = each %hash ) {
push @{$ordered{$value-{ip}}}, {$key, $value};
}
#print Dumper \%ordered;
my $i = 1;
for my $key (keys %ordered) {
print ip number $i : $key\n;
for my $entry (@{$ordered{$key}}) {
print $entry . \n;
}
++$i;
}

But this module seems to be the way to go.

--
Vincent Lequertier
vincentlequertier.tk

Le 2015-07-17 23:19, Charles DeRykus a écrit :

Another approach using Tie::IxHash:

use Tie::IxHash;
use Data::Dumper;
use feature 'say';

my @ip = (...)
my %hash = (...);

tie( my %ordered, 'Tie::IxHash', map { ( $_,[ ] ) }   @ip );

while ( my($key,$value) = each %hash ) {
push @{$ordered{$value-{ip}}}, {$key,$value};
}
say Dumper \%ordered;

Leaving exact details of printing as an exercise for reader...

--
Charles DeRykus

On Fri, Jul 17, 2015 at 6:11 AM, Vincent Lequertier s...@riseup.net 
wrote:

Hi,

I have the following structure :

$hash{$date} = {
'ip' = $ip,
'action'   = $action,
};

witch produce data like :

$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
  'ip' = 'xxx.xxx.xxx.xxx',
  'action' = 'GET xxx'
};

and an array of ip addresses, say @ip

My question is how can I display the content of %hash in the order of 
@ip,

assuming %hash has the same length as @ip ?

Thank you

--
Vincent Lequertier
vincentlequertier.tk

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Display a hash in the order of an array

2015-07-17 Thread Vincent Lequertier

Hi,

I have the following structure :

$hash{$date} = {
'ip' = $ip,
'action'   = $action,
};

witch produce data like :

$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
  'ip' = 'xxx.xxx.xxx.xxx',
  'action' = 'GET xxx'
};

and an array of ip addresses, say @ip

My question is how can I display the content of %hash in the order of 
@ip, assuming %hash has the same length as @ip ?


Thank you

--
Vincent Lequertier
vincentlequertier.tk

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Vincent Lequertier
 maio_12 maio_13 maio_14 maio_15 mcluster numreqbpc
 numreqcs3cs4bpc numreqe2abpc numreqegprsbpc odpdchlimit sas sctype sdcch
 tn_0 tn_1 tn_2 tn_3 tn_4 tn_5 tn_6 tn_7 tn7bcch tnbcch tsc userdata
 ch_group_13 chgr_tg chgr_state band bccd bspwrt cbch ccch dchno_0
 dchno_1 dchno_2 dchno_3 dchno_4 dchno_5 dchno_6 dchno_7 dchno_8 dchno_9
 dchno_10 dchno_11 dchno_12 dchno_13 dchno_14 dchno_15 dchno_16 dchno_17
 dchno_18 dchno_19 dchno_20 dchno_21 dchno_22 dchno_23 dchno_24 dchno_25
 dchno_26 dchno_27 dchno_28 dchno_29 dchno_30 dchno_31 eacpref etchtn_0
 etchtn_1 etchtn_2 etchtn_3 etchtn_4 etchtn_5 etchtn_6 etchtn_7 exchgr
 hop hoptype hsn maio_0 maio_1 maio_2 maio_3 maio_4 maio_5 maio_6 maio_7
 maio_8 maio_9 maio_10 maio_11 maio_12 maio_13 maio_14 maio_15 mcluster
 numreqbpc numreqcs3cs4bpc numreqe2abpc numreqegprsbpc odpdchlimit sas
 sctype sdcch tn_0 tn_1 tn_2 tn_3 tn_4 tn_5 tn_6 tn_7 tn7bcch tnbcch tsc
 userdata ch_group_14 chgr_tg chgr_state band bccd bspwrt cbch ccch
 dchno_0 dchno_1 dchno_2 dchno_3 dchno_4 dchno_5 dchno_6 dchno_7 dchno_8
 dchno_9 dchno_10 dchno_11 dchno_12 dchno_13 dchno_14 dchno_15 dchno_16
 dchno_17 dchno_18 dchno_19 dchno_20 dchno_21 dchno_22 dchno_23 dchno_24
 dchno_25 dchno_26 dchno_27 dchno_28 dchno_29 dchno_30 dchno_31 eacpref
 etchtn_0 etchtn_1 etchtn_2 etchtn_3 etchtn_4 etchtn_5 etchtn_6 etchtn_7
 exchgr hop hoptype hsn maio_0 maio_1 maio_2 maio_3 maio_4 maio_5 maio_6
 maio_7 maio_8 maio_9 maio_10 maio_11 maio_12 maio_13 maio_14 maio_15
 mcluster numreqbpc numreqcs3cs4bpc numreqe2abpc numreqegprsbpc
 odpdchlimit sas sctype sdcch tn_0 tn_1 tn_2 tn_3 tn_4 tn_5 tn_6 tn_7
 tn7bcch tnbcch tsc userdata ch_group_15 chgr_tg chgr_state band bccd
 bspwrt cbch ccch dchno_0 dchno_1 dchno_2 dchno_3 dchno_4 dchno_5 dchno_6
 dchno_7 dchno_8 dchno_9 dchno_10 dchno_11 dchno_12 dchno_13 dchno_14
 dchno_15 dchno_16 dchno_17 dchno_18 dchno_19 dchno_20 dchno_21 dchno_22
 dchno_23 dchno_24 dchno_25 dchno_26 dchno_27 dchno_28 dchno_29 dchno_30
 dchno_31 eacpref etchtn_0 etchtn_1 etchtn_2 etchtn_3 etchtn_4 etchtn_5
 etchtn_6 etchtn_7 exchgr hop hoptype hsn maio_0 maio_1 maio_2 maio_3
 maio_4 maio_5 maio_6 maio_7 maio_8 maio_9 maio_10 maio_11 maio_12
 maio_13 maio_14 maio_15 mcluster numreqbpc numreqcs3cs4bpc numreqe2abpc
 numreqegprsbpc odpdchlimit sas sctype sdcch tn_0 tn_1 tn_2 tn_3 tn_4
 tn_5 tn_6 tn_7 tn7bcch tnbcch tsc userdata
 
 Best Regards
 Anirban.

-- 
Vincent Lequertier
s...@riseup.net
.vincentlequertier.tk

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: last statement in a package

2015-05-21 Thread Vincent Lequertier
From http://perldoc.perl.org/perlmod.html#Perl-Modules, 1; is used to 
end with a true value


---
Vincent Lequertier
s...@riseup.net

Le 2015-05-21 08:13, Sunita Pradhan a écrit :

Hi
Why a perl programmer use 1 or any number as last statement in module
or package (like : 1;)?I checked without that also package gets loaded
.
Can somebody please explain properly , it would be good with examples ?
ThanksSunita


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl array question

2015-05-06 Thread Vincent Lequertier
Thank you for the review, I'm learning and didn't know about this way of 
using hashes :-)


---
Vincent Lequertier
s...@riseup.net

Le 2015-05-06 11:09, Shlomi Fish a écrit :

Hi Vincent,

On Wed, 06 May 2015 10:07:41 +0200
Vincent Lequertier s...@riseup.net wrote:


It's a bit ugly, but here is one way to do it :



Your code encourages many bad practices. Some notes are:


#!/usr/bin/perl


no use strict;/use warnings;:

http://perl-begin.org/tutorials/bad-elements/#no-strict-and-warnings


my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4',
'1902-5', '1902-6', '1902-7', '1902-8');
my $num1900 = 'EARFCN=1900, PCID=';
my $num1902 = 'EARFCN=1902, PCID=';


That's varvarname:

http://perl-begin.org/tutorials/bad-elements/#varvarname


for (@array) {


Iterating using $_:

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore


 # print $_ . \n;
 $num1900 .= (split '-', $_)[1] . ''
 if $_ =~ /1900/;
 $num1902 .= (split '-', $_)[1] . ''
 if $_ =~ /1902/;


Duplicate code and you really should use a datastructure and less error 
prone

parsing.


}
$num1900 =~ s/\$/;/;
$num1902 =~ s/\$/;/;


 has no special meaning in regexes , so there is no reason to 
backslash it

(it doesn't hurt though).


print $num1900 . \n;
print $num1902;


There should be a newline here too for good measure.

Regards,

Shlomi Fish


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl array question

2015-05-06 Thread Vincent Lequertier

It's a bit ugly, but here is one way to do it :

#!/usr/bin/perl
my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4', 
'1902-5', '1902-6', '1902-7', '1902-8');

my $num1900 = 'EARFCN=1900, PCID=';
my $num1902 = 'EARFCN=1902, PCID=';
for (@array) {
# print $_ . \n;
$num1900 .= (split '-', $_)[1] . ''
if $_ =~ /1900/;
$num1902 .= (split '-', $_)[1] . ''
if $_ =~ /1902/;
}
$num1900 =~ s/\$/;/;
$num1902 =~ s/\$/;/;
print $num1900 . \n;
print $num1902;

Cheers !
---
Vincent Lequertier
s...@riseup.net

Le 2015-05-06 09:19, Anirban Adhikary a écrit :

Hi List
I have the following array ---
('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
There are two part for each element separated by a dash.
first one known as earfcn and second one is pcid .
The requirement is  For the same “earfcn”, concatenate the “pcid” 
values

using  separator between values.
so the output will be like this
EARFCN=1900,PCID=0124;
EARFCN=1902,PCID=5678;

I am not able to generate any idea how to adress this isuue. Please 
give me

some starting point.

Best Regards
Anirban.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Not working example - from Mastering Perl book

2015-05-03 Thread Vincent Lequertier
Same output here, with perl 5, version 20, subversion 2 (v5.20.2) built
for x86_64-linux-thread-multi.

I'm from package main
My name is glob
I'm from package main
My name is glob

Le 03/05/2015 10:01, Octavian Rasnita a écrit :
 Hello,
 
 I've seen the following example in Mastering Perl book, with the comment
 at the end telling what should be the result:
 
 #!/usr/bin/perl
 # typeglob-name-package.pl
 use v5.10;
 
 $foo = Some value;
 $bar = Another value;
 
 who_am_i( *foo );
 who_am_i( *bar );
 
 sub who_am_i {
 local *glob = shift;
 
 say I'm from package  . *glob{PACKAGE};
 say My name is  . *glob{NAME};
 }
 
 Although this probably has limited usefulness, at least outside of any
 debugging, the
 output tells me more about the typeglobs I passed to the function:
 
 I'm from package main
 My name is foo
 I'm from package main
 My name is bar
 
 --- end of text from book ---
 
 I ran the code above with StrawberryPerl 5.20 and ActivePerl 5.16 and
 5.14 and it gave the following result:
 
 I'm from package main
 My name is glob
 I'm from package main
 My name is glob
 
 So it doesn't print the original name of the typeglob (foo or bar).
 Is the code above working for you as wrote in the book?
 
 --Octavian
 
 

-- 
Vincent Lequertier
s...@riseup.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to create a LO spreadsheet

2015-04-29 Thread Vincent Lequertier
Le 28/04/2015 21:23, lee a écrit :
 Vincent Lequertier s...@riseup.net writes:
 
 Le 2015-04-26 14:27, lee a écrit :
 Hi,

 how can I create a libreoffice spreadsheet with perl?  There seem to be
 two modules for it, yet none of them seems to let you do it --- if they
 do, the documentation doesn't have any example of how to do it.

 The alternative seems to be to write MS excel files, and I don't really
 want to resort to that.


 --
 Again we must be afraid of speaking of daemons for fear that daemons
 might swallow us.  Finally, this fear has become reasonable.

 This module let you create ods spreadsheets.

 https://metacpan.org/pod/Spreadsheet::Wright
 
 Thank you, that looks quite promising :)
 
 Do you know any way to have libreoffice display images in a document
 when I specify the URL of an image file which resides on a web server?
 Apparently, best it can do is only to display the URL as hyperlink,
 which, of course, is very useless.  The spreadsheet I need to create
 will contain such URLs.
 
 

I don't know. In LO when using insert - image and inserting
'http://www.google.com/images/logo.png' as file name, it works.
However, no modules seem to provide such feature. Maybe you should
rely on the LO API.

-- 
Vincent Lequertier
s...@riseup.net

-- 
Vincent Lequertier
s...@riseup.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to create a LO spreadsheet

2015-04-27 Thread Vincent Lequertier

Le 2015-04-26 14:27, lee a écrit :

Hi,

how can I create a libreoffice spreadsheet with perl?  There seem to be
two modules for it, yet none of them seems to let you do it --- if they
do, the documentation doesn't have any example of how to do it.

The alternative seems to be to write MS excel files, and I don't really
want to resort to that.


--
Again we must be afraid of speaking of daemons for fear that daemons
might swallow us.  Finally, this fear has become reasonable.


This module let you create ods spreadsheets.

https://metacpan.org/pod/Spreadsheet::Wright

Hope that helps.

--
Vincent Lequertier
s...@riseup.net

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to filter out { } block in text file

2010-11-17 Thread Vincent Li
On Wed, Nov 17, 2010 at 3:26 AM, Rob Dixon rob.di...@gmx.com wrote:
 On 16/11/2010 17:01, Vincent Li wrote:

 Hi List,

 I have a text test.txt file looks like below:

 stp instance 0 {
    interfaces 1.1 {
          external path cost 2
          internal path cost 2
       }
    vlans {
       internal
       vlan10
    }
 }
 profile http http_global {
    defaults from http
    max header size 38912
    encrypt cookies {
       F-P-SES
    }
 }
 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
    delayed acks enable
    proxy mss disable
 }
 vlan vlan10 {
    tag 1330
    interfaces tagged 1.1
 }
 route domain 10 {
    parent id 0
    description RD10
    vlans vlan10
 }
 route domain 12 {
    parent id 10
    description RD12
    vlans vlan12
 }

 how can I find a specific profile { } block and remove/replace that
 part from the file, for example, I want to remove below block or
 replace it with emtpy blank line

 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
    delayed acks enable
    proxy mss disable
 }

 and the { } could have nested { } block too.

 I tried:

 perl -e '$/=undef;foreach $profile (=~m/profile.*?{.*?}/gs) { print
 $profile\n; }'  /tmp/test.txt

 to search and print out the all profile, any tips/sample codes would
 be very much apprecaited.

 Hi Vincent

 It is correct that arbitrarily nested blocks cannot be parsed with a single
 regular expression, but there is also no need for anything elaborate.

 The program below simply keeps track of the level of nesting by adding the
 number of opening braces and subtracting the number of closing braces on
 each line of the data file. When the level reaches zero a complete block has
 been read and its label determines whether or not it should be output.

 HTH,

 Rob


 use strict;
 use warnings;

 my %exclude;
 while(DATA) {
  chomp;
  next unless /(\w[\w\s-]*\w)/;
  $exclude{$1}++;
 }

 open my $profile, '', 'profile.txt' or die $!;

 my $label = '';
 my $block = '';
 my $level = 0;

 while ($profile) {

  if ($level == 0 and /(\w[\w\s-]*\w)/) {
    $label = $1;
  }

  $block .= $_;

  $level += tr/{//;
  $level -= tr/}//;

  if ($level == 0) {
    if (not $exclude{$label}) {
      print $block;
    }
    $block = $label = '';
  }
 }

 __DATA__
 profile auth ssl_ocsp
 profile stats stats
 profile stream stream
 profile auth tacacs
 profile tcp tcp
 profile tcp tcp-cell-optimized
 profile tcp tcp-lan-optimized
 profile tcp tcp-wan-optimized
 profile udp udp


Thanks everyone replied, I found two similar links on stackflow:

http://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns
http://stackoverflow.com/questions/2700613/how-can-i-extract-a-string-between-matching-braces-in-perl

so looks like there are three options:

1, single magic regex
2, use Text::Balanced
3, plain Perl script to trace {}
4, parser

I tried 1 so far for various regex from the stackoverflow link above,
no success so far. will try 2, then 3.

Thanks.

Vincent

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to filter out { } block in text file

2010-11-17 Thread Vincent Li
On Wed, Nov 17, 2010 at 3:26 AM, Rob Dixon rob.di...@gmx.com wrote:
 On 16/11/2010 17:01, Vincent Li wrote:

 Hi List,

 I have a text test.txt file looks like below:

 stp instance 0 {
    interfaces 1.1 {
          external path cost 2
          internal path cost 2
       }
    vlans {
       internal
       vlan10
    }
 }
 profile http http_global {
    defaults from http
    max header size 38912
    encrypt cookies {
       F-P-SES
    }
 }
 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
    delayed acks enable
    proxy mss disable
 }
 vlan vlan10 {
    tag 1330
    interfaces tagged 1.1
 }
 route domain 10 {
    parent id 0
    description RD10
    vlans vlan10
 }
 route domain 12 {
    parent id 10
    description RD12
    vlans vlan12
 }

 how can I find a specific profile { } block and remove/replace that
 part from the file, for example, I want to remove below block or
 replace it with emtpy blank line

 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
    delayed acks enable
    proxy mss disable
 }

 and the { } could have nested { } block too.

 I tried:

 perl -e '$/=undef;foreach $profile (=~m/profile.*?{.*?}/gs) { print
 $profile\n; }'  /tmp/test.txt

 to search and print out the all profile, any tips/sample codes would
 be very much apprecaited.

 Hi Vincent

 It is correct that arbitrarily nested blocks cannot be parsed with a single
 regular expression, but there is also no need for anything elaborate.

 The program below simply keeps track of the level of nesting by adding the
 number of opening braces and subtracting the number of closing braces on
 each line of the data file. When the level reaches zero a complete block has
 been read and its label determines whether or not it should be output.

 HTH,

 Rob


 use strict;
 use warnings;

 my %exclude;
 while(DATA) {
  chomp;
  next unless /(\w[\w\s-]*\w)/;
  $exclude{$1}++;
 }

 open my $profile, '', 'profile.txt' or die $!;

 my $label = '';
 my $block = '';
 my $level = 0;

 while ($profile) {

  if ($level == 0 and /(\w[\w\s-]*\w)/) {
    $label = $1;
  }

  $block .= $_;

  $level += tr/{//;
  $level -= tr/}//;

  if ($level == 0) {
    if (not $exclude{$label}) {
      print $block;
    }
    $block = $label = '';
  }
 }

 __DATA__
 profile auth ssl_ocsp
 profile stats stats
 profile stream stream
 profile auth tacacs
 profile tcp tcp
 profile tcp tcp-cell-optimized
 profile tcp tcp-lan-optimized
 profile tcp tcp-wan-optimized
 profile udp udp


your drop in script works, I guess plain old logic wins this time :)
did minor modification to the regex since I also have _ or maybe other
characters in the file.

if ($level == 0 and /^(.*?)\s\{$/)

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How to filter out { } block in text file

2010-11-16 Thread Vincent Li
Hi List,

I have a text test.txt file looks like below:

stp instance 0 {
   interfaces 1.1 {
 external path cost 2
 internal path cost 2
  }
   vlans {
  internal
  vlan10
   }
}
profile http http_global {
   defaults from http
   max header size 38912
   encrypt cookies {
  F-P-SES
   }
}
profile tcp tcp {
   reset on timeout enable
   time wait recycle enable
   delayed acks enable
   proxy mss disable
}
vlan vlan10 {
   tag 1330
   interfaces tagged 1.1
}
route domain 10 {
   parent id 0
   description RD10
   vlans vlan10
}
route domain 12 {
   parent id 10
   description RD12
   vlans vlan12
}

how can I find a specific profile { } block and remove/replace that
part from the file, for example, I want to remove below block or
replace it with emtpy blank line

profile tcp tcp {
   reset on timeout enable
   time wait recycle enable
   delayed acks enable
   proxy mss disable
}

and the { } could have nested { } block too.

I tried:

perl -e '$/=undef;foreach $profile (=~m/profile.*?{.*?}/gs) { print
$profile\n; }'  /tmp/test.txt

to search and print out the all profile, any tips/sample codes would
be very much apprecaited.

Thanks

Vincent

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to filter out { } block in text file

2010-11-16 Thread Vincent Li
On Tue, Nov 16, 2010 at 9:38 AM, Jim Gibson jimsgib...@gmail.com wrote:
 On 11/16/10 Tue  Nov 16, 2010  9:01 AM, Vincent Li
 vincent.mc...@gmail.com scribbled:

 Hi List,

 I have a text test.txt file looks like below:

 stp instance 0 {
    interfaces 1.1 {
          external path cost 2
          internal path cost 2
       }
    vlans {
       internal
       vlan10
    }
 }
 profile http http_global {
    defaults from http
    max header size 38912
    encrypt cookies {
       F-P-SES
    }
 }

 [snip]

 how can I find a specific profile { } block and remove/replace that
 part from the file, for example, I want to remove below block or
 replace it with emtpy blank line

 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
    delayed acks enable
    proxy mss disable
 }

 and the { } could have nested { } block too.


 You need a parser to do this right. You might have some luck by reading the
 entire file into a scalar variable and using the Text::Balanced module
 together with some regular expressions to extract and parse the various
 blocks within the file.

 A more rigorous approach would be to create a real parser with the
 Parse::RecDescent module and create a grammar for your file. However, that
 module has a steep learning curve and can be slow.

thanks for the reply, maybe I just make everyone think too deep for
this problem, if that is true, sorry about that. let me rephrase what
I want to achieve. the file look like this:

vlan vlan10 {
   tag 1330
   interfaces tagged 1.1
}
route domain 10 {
   parent id 0
   description RD10
   vlans vlan10
}
profile smtp smtp {
   defaults from none
   security enabled enable
}
profile oneconnect oneconnect_global {
   defaults from oneconnect
}
profile tcp tcp {
   reset on timeout enable
   time wait recycle enable
}
self 10.99.91.1 {
   netmask 255.255.255.0
   vlan vlan11
   allow default
}
failover {
   standby link down time 0
}

My aim is to remove specific profile.*{} block from that file, I have
an half working script I wrote here:

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

my $holdTerminator = $/;
undef $/;
open(my $fh, '', /tmp/test1.scf) or die $!;
my $text = $fh;
while(DATA) {
chop;
$text =~ s/$_\s{.*?}//gs;
}
#$text =~ s/profile tcp tcp\s{.*?}//gs;
print $text;
$/ = $holdTerminator;

__DATA__
profile auth ssl_ocsp
profile stats stats
profile stream stream
profile auth tacacs
profile tcp tcp
profile tcp tcp-cell-optimized
profile tcp tcp-lan-optimized
profile tcp tcp-wan-optimized
profile udp udp


my intention is to find any profile list in __DATA__ and remove the
whole block from that file, now the problem is in the while loop, it
appear that the regex and substituation is not working, but if comment
out the while loop block and hard code the profile pattern in the
subsituation regex, it works, what I am missing?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to filter out { } block in text file

2010-11-16 Thread Vincent Li
On Tue, Nov 16, 2010 at 1:11 PM, Shawn H Corey shawnhco...@gmail.com wrote:
 On 10-11-16 04:07 PM, Vincent Li wrote:

 My aim is to remove specific profile.*{} block from that file

 Yes, but if the {} blocks are nestable, then you can't do it with regular
 expressions alone.


right, I only have one level nested {}, any tips? when file is slurped
to file mode, the nested {} will look like 'profile foo  { foo  { foo
} foo  }profile bar  { bar  { bar } bar  }profile goo { goo } ', I
tried regex:

{.*?(?:{.*?})?.*?}

but it is not working.

Vincent

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to filter out { } block in text file

2010-11-16 Thread Vincent Li
On Tue, Nov 16, 2010 at 2:14 PM, Jim Gibson jimsgib...@gmail.com wrote:
 On 11/16/10 Tue  Nov 16, 2010  1:07 PM, Vincent Li
 vincent.mc...@gmail.com scribbled:

 On Tue, Nov 16, 2010 at 9:38 AM, Jim Gibson jimsgib...@gmail.com wrote:


 You need a parser to do this right. You might have some luck by reading the
 entire file into a scalar variable and using the Text::Balanced module
 together with some regular expressions to extract and parse the various
 blocks within the file.

 A more rigorous approach would be to create a real parser with the
 Parse::RecDescent module and create a grammar for your file. However, that
 module has a steep learning curve and can be slow.

 thanks for the reply, maybe I just make everyone think too deep for
 this problem, if that is true, sorry about that. let me rephrase what
 I want to achieve. the file look like this:

 vlan vlan10 {
    tag 1330
    interfaces tagged 1.1
 }
 route domain 10 {
    parent id 0
    description RD10
    vlans vlan10
 }
 profile smtp smtp {
    defaults from none
    security enabled enable
 }
 profile oneconnect oneconnect_global {
    defaults from oneconnect
 }
 profile tcp tcp {
    reset on timeout enable
    time wait recycle enable
 }
 self 10.99.91.1 {
    netmask 255.255.255.0
    vlan vlan11
    allow default
 }
 failover {
    standby link down time 0
 }

 My aim is to remove specific profile.*{} block from that file, I have
 an half working script I wrote here:

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

 my $holdTerminator = $/;
 undef $/;
 open(my $fh, '', /tmp/test1.scf) or die $!;
 my $text = $fh;
 while(DATA) {
 chop;

 Try chomp here instead of chop.

 $text =~ s/$_\s{.*?}//gs;
 }
 #$text =~ s/profile tcp tcp\s{.*?}//gs;
 print $text;
 $/ = $holdTerminator;

 __DATA__
 profile auth ssl_ocsp
 profile stats stats
 profile stream stream
 profile auth tacacs
 profile tcp tcp
 profile tcp tcp-cell-optimized
 profile tcp tcp-lan-optimized
 profile tcp tcp-wan-optimized
 profile udp udp


 my intention is to find any profile list in __DATA__ and remove the
 whole block from that file, now the problem is in the while loop, it
 appear that the regex and substituation is not working, but if comment
 out the while loop block and hard code the profile pattern in the
 subsituation regex, it works, what I am missing?

 What platform are you using? I did have the same problem until I made sure
 there were only linefeeds in the file and I used chomp instead of chop. The
 search pattern I was reading from DATA contained a carriage return \r on
 the end.

 Run your output through a hex/octal dump program, e.g. on unix:

 perl program.pl | od -c

 to see the characters, and print the search patterns you read from DATA in
 your program:

 while(my $pat = DATA) {
  chomp($pat);
  print Apply $pat\n;
  $text =~ s/$pat\s{.*?}//gs;
 }

Jim, thanks for the tips, I got it working now, but not with nested {}
block, I am running out of idea on the nested {} block issue, the
parser route seems complicate to me as my Perl is still rough :)

Vincent

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




What is the error in this code

2010-03-31 Thread Vincent Cannavale

#open a text file for reading, since opening for writing wipes the file
open(INFILE, perlfile.txt);
#assign the file, identified by the file handle to an array, then transform
#the array into a scalar variable by joining each element in the array
#(a line) with a new line character
$variable = join(@variable = INPUT, \n);
close(INFILE);
open(OUTFILE, perlfile.txt);

$variable =~ s/0/zero/g ;
$variable =~ s/1/one/g ;
$variable =~ s/2/two/g ;
$variable =~ s/3/three/g ;
$variable =~ s/4/four/g ;
$variable =~ s/5/five/g ;
$variable =~ s/6/six/g ;
$variable =~ s/7/seven/g ;
$variable =~ s/8/eight/g ;
$variable =~ s/9/nine/g ;

#print the changed text back to the file and close it.
print OUTFILE $variable;
close(OUTFILE);


Simple perl math caculation question

2007-07-10 Thread Vincent Li


I am trying to experiment a simple perl math caculation script I wrote:

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

my %operator = (
minus = '-',
add = '+',
multiply = '*',
divide = '/',
);

my $big = 5;
my $small = 2;

for (values %operator) {

my $result = $big  $_ $small;

print $result\n;

}

I know the my $result = $big $_ $small is not valid perl expression,and 
may look stupid :) but you get the idea that I want to achieve that 
because the operator is stored in a varible and unknown to me. I guess 
there is other way around, I am just not aware of.


Thanks in advance

Vincent

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




Re: Simple perl math caculation question

2007-07-10 Thread Vincent Li

On Tue, 10 Jul 2007, Chas Owens wrote:


On 7/10/07, Vincent Li [EMAIL PROTECTED] wrote:


 I am trying to experiment a simple perl math caculation script I wrote:

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

 my %operator = (
  minus = '-',
  add = '+',
  multiply = '*',
  divide = '/',
) ;

 my $big = 5;
 my $small = 2;

 for (values %operator) {

 my $result = $big  $_ $small;

 print $result\n;

}

 I know the my $result = $big $_ $small is not valid perl expression,and
 may look stupid :) but you get the idea that I want to achieve that
 because the operator is stored in a varible and unknown to me. I guess
 there is other way around, I am just not aware of.

 Thanks in advance

 Vincent


A better way to construct this is with anonymous subroutines:

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

my %operator = (
   minus= sub { (shift) - shift },
   add  = sub { (shift) + shift },
   multiply = sub { (shift) * shift },
   divide   = sub { (shift) / shift },
);

my $big = 5;
my $small = 2;

for my $key (keys %operator) {
   my $op = $operator{$key};
   my $result = $op-($big, $small);
   print $key: $big and $small = $result\n;
}



Ah, Thanks guys, that is what I want.

Vincent

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




Re: [SPAM] perl 5.8.8 install problem

2007-05-08 Thread Vincent Li

On Tue, 8 May 2007, Kevin W. Gagel wrote:


I run SpamAssassin on a RHEL 4 box with the FuzzyOCR plugin. This
combonation was sending errors to my log files so often that my server
slowed down. Follow up on the cause revealed an upgrade to 5.8.8 would
correct the problem.


Actually, you don't need to upgrade to 5.8.8 if you don't need the new 
feature which latest SpamAssassin introduced to  allow SA rules written in 
multi-bytes languages. Add use bytes back to Mail::SpamAssassin::Message 
will skip the broken SARE rules warnings. Too late you already decided to 
upgrade to 5.8.8 :)




Unfortuantly I've spent a few days cleaning up the aftermath of the
problems that were created. I'm not stuck with a few problems I can't seem
to find the answer to. I'm hoping someone here can help me out because I'm
not to up on perl yet.

Anyway, what I did was remove the current installation of perl using the
rpm command to erase it. Since it complained about dependants and I was
about to re-install it I used the nodeps option.

Then I installed perl 5.8.8 and re-installed my modules that I use.
Specifically SpamAssassin. When I try to run spamd I get this error now:
[EMAIL PROTECTED] ~]# /etc/init.d/spamassassin start
Starting spamd: Can't locate object method register_domain via package
IO::Socket::INET at
/usr/local/lib/perl5/5.8.8/i686-linux/IO/Socket/INET.pm line 22.
Compilation failed in require at /usr/bin/spamd line 44.
BEGIN failed--compilation aborted at /usr/bin/spamd line 79.
  [FAILED]
The INET installed went in with no problem and is:
cpan[12] install IO::Socket::INET
IO::Socket::INET is up to date (1.31).

My web server could not start until I commented out the following line:
#LoadModule perl_module modules/mod_perl.so

The error I get with that active is:
May  8 10:24:04 avas httpd: Syntax error on line 26 of
/etc/httpd/conf.d/perl.conf:
May  8 10:24:04 avas httpd: Invalid command 'PerlTaintCheck', perhaps
mis-spelled or defined by a module not included in the server configuration
May  8 10:24:04 avas httpd: httpd startup failed

mod_perl.so existed in the /etc/httpd/modules directory but foolishly I
deleted it thinking that re-installing the mod_perl package would bring
back the correct one. Nope - that was wrong.

So, now I don't have a mod_perl for apache and my spamassassin won't run
because of some strange perl error.

Can someone shed some light on this for me... What should I do now?



Why don't you get rid of all current perl and perl libraries and build 
from tarball source, then run the new installed cpan command to install 
modules that SA depends on



Vincent Li
http://bl0g.blogdns.com

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




Re: [SPAM] Re: perl 5.8.8 install problem

2007-05-08 Thread Vincent Li

On Tue, 8 May 2007, Kevin W. Gagel wrote:


- Original Message -

Life really sucks.  At least it sounds like it is a personal or
development machine rather than a production system.


I wish... It's my gateway email server. I've bypassed all anti-spam/perl
functions to keep it running while I figure out what to do.



I think spamd can run on seperate box, maybe it is easier/quicker to setup 
fresh SA on fresh box  than fixing the broken perl on the production email 
server.


Vincent Li
http://bl0g.blogdns.com

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




Re: [SPAM] Re: Accessing packed data structures

2007-03-14 Thread Vincent Li

On Wed, 14 Mar 2007, Dharshana Eswaran wrote:


On 3/13/07, Tom Phoenix [EMAIL PROTECTED] wrote:


 On 3/13/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

  I was going thro the topic Accessing packed data structures in the
 Perl
  Complete Reference Book. I came across this example:
 
  struct utmp {

  char ut_user[8]; /* User login name */
  char ut_id[4]; /* /etc/inittab id */
  char ut_line[12]; /* device name */
  short ut_pid; /* process ID */
  short ut_type; /* type of entry */
  struct exit_status ut_exit; /* The exit status of a process */
  /* marked as DEAD_PROCESS. */
  time_t ut_time; /* time entry was made */
 };
 
  For the above structure:
 
  The pack template given was a8a4a12l.


  I am, somehow, not able to understand how to generate the pack template
 from
  the structure's data types.

 The pieces match up this way:

 char ut_user[8]; /* User login name: a8 */
 char ut_id[4]; /* /etc/inittab id: a4 */
 char ut_line[12]; /* device name: a12 */
 short ut_pid; /* process ID: s */
 short ut_type; /* type of entry: s */
 struct exit_status ut_exit; /* The exit status of a process */
 /* marked as DEAD_PROCESS: s s */
 time_t ut_time; /* time entry was made: l */

 A char array becomes an a42, with the number being the length of the
 array. A short becomes s, and a long becomes l. (You do need to know
 something about how C stores data in memory. Note that exit_status and
 ut_exit are two variables, even though they are declared on the same
 line; that's why there are two s's in the comment.)

  Here, how does the pack and unpack play its role? What format should the
  input be in? What are the possible formats it can accept here?

 Have you seen the documentation for pack and unpack? There is a large
 table of format letters. Are you asking for something else?

 Do you have a C struct that you can't translate to a pack/unpack
 template? If so, feel free to post it here. Someone will know how to
 deal with it.

 Yes, you are right...


I have a structure and it is somethiung like this

typedef struct  _TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S

   TAPI_CALL_ID_T  callId;
   TAPI_VOICE_INCOMING_CALL_TYPE_E type;
   TAPI_PHONE_NUMBER_A phoneNumber;
   TAPI_CALL_LINE_ElineNo;
   TAPI_PHONEBOOK_NAME_A   alpha;
   } TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S;

Here the typedefs are:

TAPI_CALL_ID_T, TAPI_PHONE_NUMBER_A, TAPI_PHONEBOOK_NAME_A   = Unsigned int
8
TAPI_VOICE_INCOMING_CALL_TYPE_E = enum type
TAPI_CALL_LINE_E  = signed int 8

Now how do i come up with the pack template? I dont know how a enum should
be represented in the pack template. :-(

/I8(enum)I8i8I8/ = pack template

The above mentioned enum just contains two elements.

The data which i need to pack and unpack to these elements are in hex
format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.

I kindly request anyone to guide me in this.

Thanks and Regards,
Dharshana



What about this one:

http://search.cpan.org/~mhx/Convert-Binary-C-0.67/lib/Convert/Binary/C.pm

I once used it to solve the complex pack/unpack temlate and 
machine endianess problem


Vincent Li
http://bl0g.blogdns.com

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




P0fq.pl and pack/unpack

2007-02-20 Thread Vincent Li



I am running passive OS fingerprinting tool p0f 
http://lcamtuf.coredump.cx/p0f.shtml as:


p0f -Q /var/run/p0f.sock -0 'dst port 25'  /dev/null 

then run a test script p0fq.pl from the p0f source package.

./p0fq.pl /var/run/p0f.sock src_host 0 dst_host 25

The p0fq.pl test script works on X86 machine running Linux, but not on Mac 
running OS X/Yellow Dog Linux.


I suspect it might relate to the endianess of x86 and Mac, so by any 
chance,could any Perl gurus shed a light on me what's wrong with the p0fq.pl 
script. Should the template of pack/unpack be adjusted to fit Mac's big 
endian? I tried to use V to replace L, v to replace s,S in the template of 
pack/unpack, but still failed.


The p0fq.pl script is as following:

use strict;
use IO::Socket;
use Net::IP;

my $QUERY_MAGIC = 0x0defaced;
my $QTYPE_FINGERPRINT = 1;

die usage: p0fq.pl p0f_socket src_ip src_port dst_ip dst_port
  unless $#ARGV == 4;

# Convert the IPs and pack the request message
my $src = new Net::IP ($ARGV[1]) or die (Net::IP::Error());
my $dst = new Net::IP ($ARGV[3]) or die (Net::IP::Error());
print $ARGV[1]\n;
my $query = pack(L L L N N S S, $QUERY_MAGIC, $QTYPE_FINGERPRINT, 
0x12345678,

 $src-intip(), $dst-intip(), $ARGV[2], $ARGV[4]);

# Open the connection to p0f
my $sock = new IO::Socket::UNIX (Peer = $ARGV[0],
 Type = SOCK_STREAM);
die Could not create socket: $!\n unless $sock;

# Ask p0f
print $sock $query;
my $response = $sock;
close $sock;
# Extract the response from p0f
my ($magic, $id, $type, $genre, $detail, $dist, $link, $tos, $fw,
$nat, $real, $score, $mflags, $uptime) =
  unpack (L L C Z20 Z40 c Z30 Z30 C C C s S N, $response);
die Bad response magic.\n if $magic != $QUERY_MAGIC;
die P0f did not honor our query.\n if $type == 1;
die This connection is not (no longer?) in the cache.\n if $type == 2;

# Display result
print Genre:  . $genre . \n;
print Details  :  . $detail . \n;
print Distance :  . $dist .  hops\n;
print Link :  . $link . \n;
print Uptime   :  . $uptime .  hrs\n;

Thanks

Vincent Li
Bloghttp://bl0g.blogdns.com

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




Re: finding matches in multiple arrays

2006-09-18 Thread Vincent Li

On Mon, 18 Sep 2006, Jeff Pang wrote:




Yes, the FAQ answer is more efficient.  Using Big O notation[1], the FAQ's
solution is O(n) and your's is O(n**2)



where is the FAQ?sorry I never knew it.


You mean perldoc perlfaq? it has perlfaq1, perlfaq2...perlfaq9. If it is 
not what you asked, then I am dump :)





--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

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




Vincent Li  http://mcli.homelinux.org
System AdminThe Biomdedical Research Centre
University of British Columbia
Tel:604-822-7830
Email:  mcli [EMAIL PROTECTED] brc. ubc. ca

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




Add comment to a pattern matched file line

2006-01-10 Thread Vincent Li

Hi List:

I have two files like this:

file1:
score CN_SUBJ_PROMOTE3.100 # [0.000..3.100]
score CN_SUBJ_PROMOTION  3.600 # [0.000..3.600]
score CN_SUBJ_PROVIDE3.000 # [0.000..3.000]

file2:
CN_SUBJ_PROMOTE
CN_SUBJ_PROMOTION

If string CN_SUBJ_PROMOTE exist in file2 and file1, add comment (#) to 
file1 like:


#score CN_SUBJ_PROMOTE3.100 # [0.000..3.100]
#score CN_SUBJ_PROMOTION  3.600 #[0.000..3.600]

I came  up with this script:

#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

tie my @array1, ,'Tie::File',  file1 or die Could not tie file1!;
tie my @array2, ,'Tie::File',  file2 or die Could not tie file2!;

for (@array2) {
   my $string = $_;
  for (@array1) {
  if (/$string/) {
   s/$_/#$_/;
   }
   }
}

It did not work as I wish, any thoughts or other method to do this?

Thanks in Advance!


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




regular expression question

2005-01-17 Thread Vincent
Hi all,

I am new to perl, I receive some spam email with subject like st0ck,
0pportunities, gr0wth..., how can I match those words with number 0 in

Thanks in advance

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




mech-dump...

2003-11-15 Thread Vincent A. Primavera
Hello,
Using the mech-dump utility I get the error listed below when trying
to access this page.  I do have the login information.  Does anybody know
how I can supply it and get around this?
--
Thank you,

Vincent A. Primavera.
M.I.S. Manager.
Ralph Pill Electric Supply Co.

C:\Tempmech-dump.pl --forms http://www.road.com/clients/fleetASAP/index.pl
Can't fetch http://www.road.com/clients/fleetASAP/index.pl
401 Authorization Required


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



Get the Architecture type

2003-07-07 Thread BUFFERNE,VINCENT (HP-France,ex1)
Hi,

Within a perl script, I would like to get the architecture type of the
machine (ia32, ia64, pa-risc...).
Is there an equivalent routine to the shell call uname -a in Perl?

Thanks,

Vincent

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



RE: How to measure Array or Hash's byte size ?

2003-04-04 Thread BUFFERNE,VINCENT (HP-France,ex1)
What's about:

my @foo = ( '1', '2' ,'3' );
my $size = $#foo + 1;
print table size $size\n;

Ouput:
table size 3

Vincent

-Original Message-
From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 5:14 PM
To: [EMAIL PROTECTED]
Subject: How to measure Array or Hash's byte size ?


My method  sounds stupid, but still works :

my @array = ('123', 'abc', 'def',  1..9);
my $len_of_array =  0 ;
foreach my $elem(@array)
{$len_of_array += length($elem) }
print $len_of_array ; # I got '18'

my %hash = (1=2, 2=3, 3=4);
foreach my $key(keys(%hash))
{$len_of_hash += length($key) + length($hash{$key}) }
print $len_of_hash ; # I got '6'

I suppose there should be another better and faster way to done this, 
any suggestion ?

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



RegExp and XML

2003-02-21 Thread Vincent O' Keeffe
Hi there,

I'm downloading xml files from a mail server using POP3Client. I'm saving these mails 
as files on a directory. I also parse out certain details from the XML file to include 
in the filename.

The only problem is that, when I grab the body of the message using POP3Client's 
method, it includes mail-related information above and below the actual XML tags. 

--=_Part_15_1895070.1044374870502
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

?xml version=1.0?
...

/Order
--=_Part_15_1895070.1044374870502--


So, I need to remove everything before the opening ?xml string and, again, everything 
after the closing /Order tag. I thought about stripping out the first 4 and last 4 
lines of the file but the messages sometimes arrive clean, and sometimes with this 
extra info.

I've trawled newsgroups and the web and haven't been able to come up with any answers. 

Does anyone have any idea of how to go about this if I assign the body to a variable 
like so?

$msgbody = $pop-Body($i)   # $pop being the instantiated POP connection object

Thanks,
Vincent



RE: Join problem

2002-10-20 Thread Vincent Lee
Actually the problem was the following:

I had wanted to set the array to NULL. 

I set it as follows:
@array=;
This puts an empty string as the first array value.

the correct way is:
@array=();

Solved my problem.

-Original Message-
From: Beau E. Cox [mailto:beau;beaucox.com]
Sent: Thursday, October 17, 2002 8:08 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Join problem


Hi - it must be an undef in your array, your
join should work as posted.

You might try something like (untested):

for (@array) {
  if ($_) {
push @clean_array, $_
  }
}

now join on @clean_array...

Aloha = Beau.

-Original Message-
From: Vincent Lee [mailto:vjlee_us;yahoo.com]
Sent: Thursday, October 17, 2002 1:48 AM
To: [EMAIL PROTECTED]
Subject: Join problem


Hello All,

I've got a problem with the JOIN function

I've got a list of columns that gets returned from the
database.

I push the column values into an array and then join
them with a comma. The problem is that JOIN puts a
comma in the first value. 

How do I get rid of the comma in the first value?
Is the database returning a null field in the first
columns, is that why it's returning a comma?

join (,,@columns);

=
Regards,
Vincent

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

-- 
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]




Join problem

2002-10-18 Thread Vincent Lee
Hello All,

I've got a problem with the JOIN function

I've got a list of columns that gets returned from the
database.

I push the column values into an array and then join
them with a comma. The problem is that JOIN puts a
comma in the first value. 

How do I get rid of the comma in the first value?
Is the database returning a null field in the first
columns, is that why it's returning a comma?

join (,,@columns);

=
Regards,
Vincent

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

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




Re: creating a string on the fly

2002-10-16 Thread Vincent Lee


--- Rob [EMAIL PROTECTED] wrote:
 Sorry Vincent I'm not sure what you're meaning.
 
 You've written GetColumns ($table). Does it return
 an array of column names
 as it should?
 - Original Message -
 From: Vincent Lee [EMAIL PROTECTED]
 To: Rob [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Tuesday, October 15, 2002 11:05 PM
 Subject: RE: creating a string on the fly
 
 
  Rob,
 
  I've written a subroutine do the
 getColumns($table). The problem is that
  it's passing the entire column set back and
 appending each one.
 
 
 'Passing the entire column set back' is surely what
 you want?
 
 'Appending each one' what to what?
 
 
  I just do a select of the columns based on the
 table that is sent to the
  subroutine. The code you sent me does the entire
 thing...any ideas?
 
 
 Sounds like you just need to package the inner loop
 inside a subroutine:
 
 sub CreateView
 {
 $table = shift;
 
 print CREATE VIEW_$table AS\n;
 print SELECT (;
 
 $n = 0;
 foreach $column ( GetColumns ($table) )
 {
 print ,  if $n++;
 print $column;
 }
 print ) FROM $table;\n;
 }
 
 Am I reading you right?
 
 R
 
 
  -Original Message-
  From: Rob [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, October 15, 2002 11:38 AM
  To: [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Subject: Re: creating a string on the fly
 
 
  Two problems here.
 
  1/ Getting the tables' names and columns from the
 database.
 
  2/ Constructing the SQL from that information.
 
  The second part is easy:
 
  foreach $table ( GetTables() )
  {
  print CREATE VIEW_$table AS\n;
  print SELECT (;
 
  $n = 0;
  foreach $column ( GetColumns ($table) )
  {
  print ,  if $n++;
  print $column;
  }
  print ) FROM $table;\n;
  }
 
  Which may be enough for you.
 
 
  GetTables() and GetColumns() are the first part,
 and I can't say any more
  about what these might do without knowing more
 about what interface you
 have
  with the database.
 
  HTH
 
  Rob
 
  - Original Message -
  From: Vincent Lee [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Tuesday, October 15, 2002 3:37 PM
  Subject: Re: creating a string on the fly
 
 
 
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 


=
Regards,
Vincent

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

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




Re: creating a string on the fly

2002-10-16 Thread Vincent Lee

Here's the code:

 sub GetColumns{
my @columns=;
$statement=uc(SELECT colname from
syscat.columns where tabname='$_[0]' and
tabschema='$sch' ORDER BY colno);
$s=$dbHandle-prepare($statement) or die
Select error. Check the syntax\n;

$s- execute() or die error here.;

$s-bind_columns(\$colname);

while ($s-fetch()){
push (@columns, $colname);
   }
return @columns;
}
--- Rob [EMAIL PROTECTED] wrote:
 Sorry Vincent I'm not sure what you're meaning.
 
 You've written GetColumns ($table). Does it return
 an array of column names
 as it should?
 - Original Message -
 From: Vincent Lee [EMAIL PROTECTED]
 To: Rob [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Tuesday, October 15, 2002 11:05 PM
 Subject: RE: creating a string on the fly
 
 
  Rob,
 
  I've written a subroutine do the
 getColumns($table). The problem is that
  it's passing the entire column set back and
 appending each one.
 
 
 'Passing the entire column set back' is surely what
 you want?
 
 'Appending each one' what to what?
 
 
  I just do a select of the columns based on the
 table that is sent to the
  subroutine. The code you sent me does the entire
 thing...any ideas?
 
 
 Sounds like you just need to package the inner loop
 inside a subroutine:
 
 sub CreateView
 {
 $table = shift;
 
 print CREATE VIEW_$table AS\n;
 print SELECT (;
 
 $n = 0;
 foreach $column ( GetColumns ($table) )
 {
 print ,  if $n++;
 print $column;
 }
 print ) FROM $table;\n;
 }
 
 Am I reading you right?
 
 R
 
 
  -Original Message-
  From: Rob [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, October 15, 2002 11:38 AM
  To: [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Subject: Re: creating a string on the fly
 
 
  Two problems here.
 
  1/ Getting the tables' names and columns from the
 database.
 
  2/ Constructing the SQL from that information.
 
  The second part is easy:
 
  foreach $table ( GetTables() )
  {
  print CREATE VIEW_$table AS\n;
  print SELECT (;
 
  $n = 0;
  foreach $column ( GetColumns ($table) )
  {
  print ,  if $n++;
  print $column;
  }
  print ) FROM $table;\n;
  }
 
  Which may be enough for you.
 
 
  GetTables() and GetColumns() are the first part,
 and I can't say any more
  about what these might do without knowing more
 about what interface you
 have
  with the database.
 
  HTH
 
  Rob
 
  - Original Message -
  From: Vincent Lee [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Tuesday, October 15, 2002 3:37 PM
  Subject: Re: creating a string on the fly
 
 
 
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 


=
Regards,
Vincent

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

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




Re: creating a string on the fly

2002-10-15 Thread Vincent Lee

I'm starting with data in the database. It's SQL statements and I'm 
populating arrays in perl.

I don't need to build a hash but the statement. I thought an array or hash 
would be the easiest.

[EMAIL PROTECTED] wrote:

Vincent

I will have several suggestions, but I need to know what data you're
starting with, and what form it's in. Are you starting with a real database
or just a paper specification? Is the hash you're describing something you
need to build anyway or is it simply a means to build the SQL statement?

Bring the answer back to the mail group so that others can learn.

Cheers,

Rob

- Original Message -
From: Vincent Lee [EMAIL PROTECTED]
To: Rob [EMAIL PROTECTED]
Sent: Tuesday, October 15, 2002 3:03 PM
Subject: Re: creating a string on the fly


 Hi Rob,

 Thanks for helping me out!!

 Yes you are correct...hmmm...so yes, I didn't
 understand what I was doing (new to perl).

 Any suggestions on what I could do?

 I just want to be able to create a string that takes
 this information and makes a create view statement

 CREATE VIEW_$TABLENAME AS SELECT [array of
 columns]


 --- Rob [EMAIL PROTECTED] wrote:
  Hi Vincent
 
  I /think/ you're misunderstanding hashes, but I need
  to make sure.
 
  Do you mean that your has array contains:
 
  ORG  = ID
  ORG  = COL1
  ORG  = COL2
  EMPLOYEE = ID
  EMPLOYEE = COL1
  EMPLOYEE = COL2
 
  Because you can't do that.
 
  A hash represents a one-to-one correspondence, so
  you can have only one
  value per
  table name. That entry can be a /list/ of columns
  though, so the way to do
  what you
  want is to set up a hash of array references:
 
  ORG  = ['ID', 'COL1', 'COL2']
  EMPLOYEE = ['ID', 'COL1', 'COL2']
 
  Tell me if I'm right.
 
  Cheers,
 
  Rob
 
  - Original Message -
  From: Vincent Lee [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Tuesday, October 15, 2002 12:55 AM
  Subject: creating a string on the fly
 
 
   Can someone help me with some basic logic?
  
   I have an array with unique tablenames from a DB
   catalog view
  
   TABNAME
   ---
   Org
   Employee
   Dept
  
   Each of these tablenames has columns in a hash
  array
  
   For example, ORG would have 3 columns and the
  array
   would be as follows:
  
   ORG  ID
   ORG  COL1
   ORG  COL2
   EMPLOYEE ID
   EMPLOYEE COL1
   EMPLOYEE COL2etc.
  
   I'm trying to build a statement that iterates
  through
   the array and builds a statement for each table.
  
   I have another array that stores just the table
  names.
  
   I can't seem to build a statement like this:
  
   ID, COL1, COl2
  
   I've got two loops one for the tables
   but then I want to test if the $table_name=keys
   (%col_hash) then print the columns...
  
  
   Anyone iwth some idea?
  
   Best regards,
   Vincent
   ___
   Vincent J. Lee
   EMAIL: [EMAIL PROTECTED] |
  [EMAIL PROTECTED]
   MOBILE: 917.318.8251
  
  
   --
   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]
 


 =
 Regards,
 Vincent

 __
 Do you Yahoo!?
 Faith Hill - Exclusive Performances, Videos  More
 http://faith.yahoo.com



Best Regards,

Vincent Lee
[EMAIL PROTECTED]
917.318.8251


___
Sent through e-mol. E-mail, Anywhere, Anytime. http://www.e-mol.com




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




Re: creating a string on the fly

2002-10-15 Thread Vincent Lee

Get Tables is a select statement from the catalog. Currently it's in an 
array..
GetTables(Columns) is also another sql statement...

I'll try and fool around with it and let you know. If you have any other 
ideas, let me know.
 
Thanks a ton for your help. This is the best support I've ever seen!!!

[EMAIL PROTECTED] wrote:

Two problems here.

1/ Getting the tables' names and columns from the database.

2/ Constructing the SQL from that information.

The second part is easy:

foreach $table ( GetTables() )
{
print CREATE VIEW_$table AS\n;
print SELECT (;

$n = 0;
foreach $column ( GetColumns ($table) )
{
print ,  if $n++;
print $column;
}
print ) FROM $table;\n;
}

Which may be enough for you.


GetTables() and GetColumns() are the first part, and I can't say any more
about what these might do without knowing more about what interface you have
with the database.

HTH

Rob

- Original Message -
From: Vincent Lee [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, October 15, 2002 3:37 PM
Subject: Re: creating a string on the fly


 I'm starting with data in the database. It's SQL statements and I'm
 populating arrays in perl.

 I don't need to build a hash but the statement. I thought an array or hash
 would be the easiest.

 [EMAIL PROTECTED] wrote:
 
 Vincent
 
 I will have several suggestions, but I need to know what data you're
 starting with, and what form it's in. Are you starting with a real
database
 or just a paper specification? Is the hash you're describing something
you
 need to build anyway or is it simply a means to build the SQL statement?
 
 Bring the answer back to the mail group so that others can learn.
 
 Cheers,
 
 Rob
 
 - Original Message -
 From: Vincent Lee [EMAIL PROTECTED]
 To: Rob [EMAIL PROTECTED]
 Sent: Tuesday, October 15, 2002 3:03 PM
 Subject: Re: creating a string on the fly
 
 
  Hi Rob,
 
  Thanks for helping me out!!
 
  Yes you are correct...hmmm...so yes, I didn't
  understand what I was doing (new to perl).
 
  Any suggestions on what I could do?
 
  I just want to be able to create a string that takes
  this information and makes a create view statement
 
  CREATE VIEW_$TABLENAME AS SELECT [array of
  columns]
 
 



Best Regards,

Vincent Lee
[EMAIL PROTECTED]
917.318.8251


___
Sent through e-mol. E-mail, Anywhere, Anytime. http://www.e-mol.com




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




RE: creating a string on the fly

2002-10-15 Thread Vincent Lee

Rob,

I've written a subroutine do the getColumns($table). The problem is that
it's passing the entire column set back and appending each one.

I just do a select of the columns based on the table that is sent to the
subroutine. The code you sent me does the entire thing...any ideas?

-Original Message-
From: Rob [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 15, 2002 11:38 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: creating a string on the fly


Two problems here.

1/ Getting the tables' names and columns from the database.

2/ Constructing the SQL from that information.

The second part is easy:

foreach $table ( GetTables() )
{
print CREATE VIEW_$table AS\n;
print SELECT (;

$n = 0;
foreach $column ( GetColumns ($table) )
{
print ,  if $n++;
print $column;
}
print ) FROM $table;\n;
}

Which may be enough for you.


GetTables() and GetColumns() are the first part, and I can't say any more
about what these might do without knowing more about what interface you have
with the database.

HTH

Rob

- Original Message -
From: Vincent Lee [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, October 15, 2002 3:37 PM
Subject: Re: creating a string on the fly


 I'm starting with data in the database. It's SQL statements and I'm
 populating arrays in perl.

 I don't need to build a hash but the statement. I thought an array or hash
 would be the easiest.

 [EMAIL PROTECTED] wrote:
 
 Vincent
 
 I will have several suggestions, but I need to know what data you're
 starting with, and what form it's in. Are you starting with a real
database
 or just a paper specification? Is the hash you're describing something
you
 need to build anyway or is it simply a means to build the SQL statement?
 
 Bring the answer back to the mail group so that others can learn.
 
 Cheers,
 
 Rob
 
 - Original Message -
 From: Vincent Lee [EMAIL PROTECTED]
 To: Rob [EMAIL PROTECTED]
 Sent: Tuesday, October 15, 2002 3:03 PM
 Subject: Re: creating a string on the fly
 
 
  Hi Rob,
 
  Thanks for helping me out!!
 
  Yes you are correct...hmmm...so yes, I didn't
  understand what I was doing (new to perl).
 
  Any suggestions on what I could do?
 
  I just want to be able to create a string that takes
  this information and makes a create view statement
 
  CREATE VIEW_$TABLENAME AS SELECT [array of
  columns]
 
 



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




Creating string on the fly

2002-10-14 Thread Vincent Lee

Can someone help me with some basic logic?

I have an array with unique tablenames from a DB
catalog view

TABNAME
---
Org
Employee
Dept

Each of these tablenames has columns in a hash array

For example, ORG would have 3 columns and the array
would be as follows:

ORG  ID
ORG  COL1
ORG  COL2
EMPLOYEE ID
EMPLOYEE COL1
EMPLOYEE COL2etc.

I'm trying to build a statement that iterates through
the array and builds a statement for each table.

I have another array that stores just the table names.

I can't seem to build a statement like this:

ID, COL1, COl2 

I've got two loops one for the tables
but then I want to test if the $table_name=keys
(%col_hash) then print the columns...


Anyone iwth some idea?

=
Regards,
Vincent

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

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




select multiple

2002-10-05 Thread Vincent van Kuler

How can I get the selected items from a select multiple

Example:

form method=post action=do_it.pl
SELECT multiple size=7 name=component-select
OPTION name=first selected value=Component_1_aSelected
Component_1/OPTION
OPTION name=secondComponent_3/OPTION
OPTION name=thirdComponent_4/OPTION
/SELECT
input type=submit value=Show_me
/form

Vincent




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




RE: Regexp

2002-09-19 Thread Panel Vincent - A53

Thank you all for your very accurate answers.

Vincent.

 -Original Message-
 From: John W. Krahn [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, September 18, 2002 7:08 PM
 To: [EMAIL PROTECTED]
 Subject: Re: Regexp
 
 
 Sudarshan Raghavan wrote:
  
  On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:
  
   I have a problem with a regular expression :
  
   I process a text file with a list of names.
  
   I would like to reformat names like
  
 Francois de   la Varenne
   Macha Meril
   BuzzMac Cormack
  
   (there must be at least two words in the name)
   to something like this :
  
   [EMAIL PROTECTED]
   [EMAIL PROTECTED]
   [EMAIL PROTECTED]
  
   In other words : [EMAIL PROTECTED].
  
   I tried the following thing and it doesn't work ($name 
 already contains one
   of those names) :
  
   $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
  
  Use split instead of a regexp (perldoc -f split)
  Let us assume the input string is in $str, this should do 
 the job for you
  
  my ($first, $rest) = split (/\s+/, $str, 2);
  $rest =~ s/\s+//g;
  print $first.$last\@domain.top;
 
 
 Very good.  Don't forget the OP wants it converted to lower case as
 well.  :-)
 
 my ( $first, $rest ) = map lc, split ' ', $str, 2;
 $rest =~ s/\s+//g;
 print $first.$last\@domain.top;
 
 
 
 John
 -- 
 use Perl;
 program
 fulfillment
 
 -- 
 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]




Regexp

2002-09-18 Thread Panel Vincent - A53

I have a problem with a regular expression :

I process a text file with a list of names.

I would like to reformat names like

  Francois de   la Varenne
Macha Meril 
BuzzMac Cormack

(there must be at least two words in the name)
to something like this :

[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

In other words : [EMAIL PROTECTED].

I tried the following thing and it doesn't work ($name already contains one
of those names) :

$name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/


Does anyone knows the right regexp to do this (I guess it's the second
expression with $s which is wrong)

Vincent Panel.

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




RE: Regexp

2002-09-18 Thread Panel Vincent - A53

 Why not splitting on whitespaces and joining the pieces together ? E.g.

Because it won't work : michael mac douglas will give
[EMAIL PROTECTED] not [EMAIL PROTECTED]

Vincent.

 -Original Message-
 From: Thorsten Dieckhoff [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, September 18, 2002 2:47 PM
 To: Panel Vincent - A53
 Subject: Re: Regexp
 
 
  I have a problem with a regular expression :
 
  I process a text file with a list of names.
 
  I would like to reformat names like
 
Francois de   la Varenne
  Macha Meril
  BuzzMac Cormack
 
  (there must be at least two words in the name)
  to something like this :
 
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
 
  In other words : [EMAIL PROTECTED].
 
  I tried the following thing and it doesn't work ($name already
 contains one
  of those names) :
 
  $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
 
 
  Does anyone knows the right regexp to do this (I guess it's the
 second
  expression with $s which is wrong)
 
  Vincent Panel.
 
 Hi, I assume you have one full name per line - why not splitting on
 whitespaces
 and joining the pieces together ? E.g.
 
 @names = split(/\s/, $line);
 $fullname = join('.', @names) . '@my.domain.foo';
 
 HTH, Thorsten !
 
 
 

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




Really newbie question

2002-08-30 Thread Panel Vincent - A53

I've made a script that looks like this


#!/usr/bin/perl -w
use Net::LDAP::LDIF;
use Net::LDAP::Entry;
$file= $ARGV[0];
open(LDIF, $file) || die Failed to open file $ARGV[0] : $!;
$ldif = Net::LDAP::LDIF-new(LDIF);
while (not $ldif-eof()) {
$entry = $ldif-read_entry();
};


Perl is giving me the following error :

Can't call method eof on undefined value at ... line ...


Is this line : $ldif = Net::LDAP::LDIF-new(LDIF); correct ? (I just want
to make a new object with the Net::LDAP::LDIF properties, what's wrong ?)

Thanks

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




LDIF file parsing

2002-08-27 Thread Panel Vincent - A53

As my first real script in perl, I would to parse a LDIF file (export format
of an LDAP directory) to get some sort of information of it. The structure
of such a file is something like this (between quotes) :


name: bozo
surname: the clown
address: over here

name: denise
surname: richard
address: in your dreams

name: brad
surname: pitt
adress: there


What should be the structure of my loop ? Do you know a complete script
already written to parse such a file (can't find any on the net) ?

Thanx,

Vincent.

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




64 bits and perl 5.6.1

2002-08-21 Thread BUFFERNE,VINCENT (Non-HP-France,ex1)

Hi all,

I want to use perl compiled in 64 bits. Do you think perl 5.6.1 is mature
enough regarding 64 bits compliance ? Do you have already test it ?
Then I want to load Shared libraries produced with XS. I would like to be
able to load either 32 bits or 64 bits shared libraries with the same perl
(compiled in 64 bits): do you know if it is possible ?

Regards,

Vincent

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




32 and 64 bits

2002-08-13 Thread BUFFERNE,VINCENT (Non-HP-France,ex1)

I want to write something like:

if (64 bits platform)
.
else
.

Where the code has a different behaviour depending on the targeted platform
(32 or 64 bits).
Do you know a simple method to perform this test in Perl ?

Thanks,

Vincent

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




XS and Shared Libraries

2002-07-17 Thread BUFFERNE,VINCENT (Non-HP-France,ex1)

Hi,

I am building a wrapper between some Perl code and C library. I am using XS
for this.
I want to compile the wrapper as a Shared Lib that is dynamically loaded by
perl.
Today I compile a Shared Lib statically linked to the C library (I link with
the C Lib.asl) in one big Shared Lib.
   
  Perl
|(load .sl)
Wrapper(including C Lib)

Now I want to be able to load the C library as Shared Lib:

  Perl
|(load .sl)
 Wrapper
|(load .sl)
  C Lib

C Lib is not a Perl library, so it cannot be loaded by Perl using
Dynaloader.
So I have two possibilities:
-either Wrapper loads dynamically C Lib
   = Wrapper includes only some XS code. Is it possible to include code
to load the C Lib within my XS code ? 
-either Wrapper is linked statically with C Lib (As you will do for an
executable)
   = Is it possible to link statically a Shared Lib with another one just
as you will do for an exectable ?

Does somebody has already face this case ? What do you advice ?

Thanks,

Vincent

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




XS and Shared Lib

2002-07-05 Thread BUFFERNE,VINCENT (Non-HP-France,ex1)

Hi,

I am writting a XS wrapper between some C bits and an executable in Perl. I
compile the wrapper as a Shared Lib and I want to load it dynamicaly from
Perl using Dynaloader.
I have done some tests with a simple Hello World like program and it work
fine, but when it comes to real thing, problems arise and at run time, I
have the following error:
Can't find 'boot_foo' symbol in foo.sl

The boot_foo function is implemented in the c file generated by xsubpp and
nothing seems to be wrong with it. 
I have tried to export PERL_DL_DEBUG=1, but the debugger does not give more
details.
I am working on HP-UX, but it should not make any deference.
Do you have any idea what could be wrong ?

Regards,

Vincent

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




select and BIG FDS

2002-05-21 Thread VINCENT BUFFERNE

Does select support big FDS (File Descriptor). This means can we use
handle larger than 2056 with select.
For example:
vec($rin,0,65536) = 1;
select($rin, undef, undef, undef);

Thanks,

Vincent


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




using vec

2002-05-17 Thread VINCENT BUFFERNE

I am using vec($foo1, $foo2, $foo3). It seems that the value of $foo3 is
limited to 2048 (with perl 5.004 or perl 5.6.1). Is it possible to use wider
values: up to 60,000 ???

Thanks,

Vincent


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




XS and Perl version

2002-04-25 Thread VINCENT BUFFERNE

I am using a XS wrapper with Perl 5.004. I am planning to go for Perl 5.6.1.
Do I have to plan modifications within the XS code ?

Thanks,

Vincent

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




Re: Access MS SQL using DBI / DBD

2001-10-31 Thread Vincent Bouttier-Deslandes

I think that the best way to do that is to use the Win32::ODBC module.
You have to create an odbc source to your SQL server db, then use the 
Win32::ODBC::new($datasource) function to bind
it.

I never find a DBI module for MSSQL, may be you can try the Sybase DBI module because 
this 2 dbs were using the same
engine...

Bye.

Erramilli, Pathi (P.) a écrit :

 Hi,

 I am new to perl...I am trying to use DBI / DBD to access MS SQL database and I 
cannot find any documentation/help.

 What I need to do is to login to the SQL server and get the database space 
details.(MS SQL 7.0  2000)

 Can someone help...Thanks in advance.

 Pathi

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

--
Vincent Bouttier-Deslandes ([EMAIL PROTECTED])
Responsable du pôle Outils/Sécurité
Tel: +33.3.28.37.78.47 - Fax : +33.3.20.67.58.43



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




Re: Perl script editor for NT/2000

2001-08-20 Thread Vincent Bouttier-Deslandes

XEmacs s is a pretty good editor too -even if it is much more bigger
than the pad and not so easy to use if you don't know anything about
Emacs ...  :-(
Visit : www.xemacs.org


Sally a écrit :

 Text pad does me,

 Sally

 -Original Message-
 From: TOM TURPIN [mailto:[EMAIL PROTECTED]]
 Sent: 20 August 2001 16:21
 To: '[EMAIL PROTECTED]'
 Subject: Perl script editor for NT/2000

 Could someone suggest a good editor for writing scripts with?

 Tom Turpin
 CAD System Administrator
 Ryobi Technologies, Inc.
 1428 Pearman Dairy Road
 Anderson, SC 29625
 Office: (864) 964-3425
 Pager: (864) 390-5195
 Fax: (864) 964-
 Email: [EMAIL PROTECTED]

 --
 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]

--
Vincent Bouttier-Deslandes ([EMAIL PROTECTED])
Responsable du pôle Outils/Sécurité
Tel: +33.3.28.37.78.47 - Fax : +33.3.20.67.58.43



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




A Variant on the Recursive Copy - Funny Problem

2001-08-16 Thread Vincent Lim

Hello All,

I am currently developing a script on Perl 5.001 in Windows 2000 but
targeted for WIndows NT 4.0.  I have scan through the list and seen the
answer on File::*.  Unfortunately, the perl version I have does not have
the FIle::Path module (or is it?).

Here's the purpose of my script.  The script runs a application that
find a set of files and empty directories that needs to be copy from
several root directories.  Unfortunately, the command must be run from a
specific directory.  So my script has to find the originating root
directory, substituing portion of the command directory.
Example:  A set of files and directories:
\PCA001\web\list.txt
\PCA013\web\mymy.txt
\PCA005\web\folder

The result of running the application command:
\Release\ACT\update_folder\web\list.txt : PCA001
\Release\ACT\update_folder\web\mymy.txt :  PCA013
\Release\ACT\update_folder\web\folder :  PCA005

Substituting to become:
\PCA001\web\list.txt
\PCA013\web\mymy.txt
\PCA005\web\folder

Once that is done, it recreates the files and directories into the
target directory.  Unfortunately, my script has ran into two problems
and I don't understand what is causing them.  The first is that the -f
file test does not seems to work.  This may be related to the second
problem.  The substitution is not occuring, which may be why it cannot
detect the file as it is poiting back to the originating directory.

I have include the code and mark the error areas with == *** Error:

Can anyone help?  TIA.

### retrieve the inpur arguments by shifting @ARGV
-#
$label = shift(@ARGV);
$voblist = shift(@ARGV);

### find the temporary directory
---#
if ($ENV{TEMP}) {
$tdir=$ENV{TEMP};
} else
{
$tdir=c:\\temp;
}

### prepare the temporary file
-#
$prog = $0;
$prog =~ s/.*\\// ;
$tmpfx = $tdir . \\. $prog . . . $$;
$tmpcmd = $tmpfx . .cmd;
$outfile = $tdir . \\output . . . txt;

### prepare set environment variable command
---#
$voblist =~ s/\\//;
$setenv = set CLEARCASE_AVOBS=;
$setenv = $setenv .  $voblist;


### prepare set viewroot mapped network drive command
--#
$drive = X:;
$dft_view = \\Update_UAT;
$destdir = y:;
$netmap = $drive . \\ . $dft_view . $voblist;

### prepare cleartool lsco command
-#
$lsco = cleartool lsco -avobs -fmt \%n;%Tf;%l\\\n;

### execute the commands
---#
CleartoolInp(
$setenv
$drive
chdir $dft_view
$lsco  $outfile
);

### parse result output for label and mkdir/copy file to destination
---#
if (-e $outfile) {
 open(OUTFILE, $outfile) or die (Error: Cannot open result file in
$tdir);
while (OUTFILE) {
if ($_ =~ /$label/) {
  ($path,$view) = split(/;/,$_);
   ($from = $path) =~ s/$dft_view/$view/i;== *** Error
   ($to = $path) =~ s/$netmap/$destdir/i;== *** Error
   if (-e $to) {
if (-f $to) { system(copy /Y $from $to); }   == *** Error
   }
   else {
if (-d $from) { system(mkdir $to); }
else {
 @dirpath = split(/\\/,$to);
 pop(@dirpath);
 $dirpath = join(\\,@dirpath);
 if (! -e $dirpath) {
  system(mkdir $dirpath); }
 system(copy /Y $from $to);
}
 } } }
 close;
}
else {
 die (Error: Cannot find $outfile);
}



### SUBROUTINES
#

### cleartoolInp - execute commands suing system process
---#
sub CleartoolInp {
 open(TMP, $tmpcmd);
 print TMP $_[0];
 close(TMP);
 system(cmd  $tmpcmd);
}










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




Re: I have a list of Directories and FIles, how do I sort them out

2001-08-16 Thread Vincent Lim

Thanks Steven,

Sorry about the missing code and program exposition.  Please see my A Variant
on the Recursive Copy - Funny Problem thread.

Best regards.
Vincent Lim

Steve Howard wrote:

 It might be helpful if you posted at least the part of the code that is
 having trouble. it's difficult to say what went wrong when we can't really
 see what is even happening.

 Steve H.

 -Original Message-
 From: Vincent Lim [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, August 15, 2001 9:35 AM
 To: [EMAIL PROTECTED]
 Subject: I have a list of Directories and FIles, how do I sort them out

 Hello,

 I have a listing of directories and files in a root directory which I
 need to recreate at another Windows NT DOS shell machine.
 The alogrithm I have implemented in general works like this:

 # check if the listing exist in target machine
 # if exist, check if it is a file in target machine
 # if file, copy file over existing file in target
 # if directory, ignore
 #  if not exist, check if it is a file in source directory
 # if file, create directory path and copy file to target
 # if directory, create directory only

 I am using the -e and -f test.  Something is jinking the test and the -f
 does not work, so all my files always end up as directories in the
 target.  What's wrong?  Or is there a better way?

 TIA.
 Vincent

 --
 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]




I have a list of Directories and FIles, how do I sort them out

2001-08-15 Thread Vincent Lim

Hello,

I have a listing of directories and files in a root directory which I
need to recreate at another Windows NT DOS shell machine.
The alogrithm I have implemented in general works like this:

# check if the listing exist in target machine
# if exist, check if it is a file in target machine
# if file, copy file over existing file in target
# if directory, ignore
#  if not exist, check if it is a file in source directory
# if file, create directory path and copy file to target
# if directory, create directory only

I am using the -e and -f test.  Something is jinking the test and the -f
does not work, so all my files always end up as directories in the
target.  What's wrong?  Or is there a better way?

TIA.
Vincent


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




Function Prototypes

2001-07-12 Thread Vincent

I'm reading the chapter on Subroutines in the camel book and have a question
about the prototypes described on page 226.
At first my understanding was, there should be a $ or @ for each parameter
expected.  Or a \@ or \$ for each reference expected.  But one of the
examples reads:

sub mysplice (\@$$@)
# called as myspice @array, @array, 0, @pushme

The $ and @ do not line up.

Also there's some prototypes with a semicolon in them

sub myindex($$;$)
# called as myindex getstring, substr
# or
# myindex getstring, substring, $start

Thanks,
Vinny