Re: uppercase strings

2003-10-08 Thread simran
Looks like you are almost there... 

% perldoc -f ucfirst


On Thu, 2003-10-09 at 13:41, Sara Gribble wrote:
> I would appreciate some help with this. I am learning
> Perl. I have a string inputed by the user. This string
> is then split, every first letter of each word in the
> string is uppercased, then joined back together and
> printed.
> 
> Here is my code, can anyone help? Thanks, Sara G.
> 
> !/usr/bin/perl
> # Demonstrating split and join when prompting the user
> for input and then changing the first letter of each
> word in a sentence to uppercase.
> 
> use strict;
> 
> print "Please enter a sentence of your choice\n";
> my $firstline = ;
> chomp ( $firstline );
> 
> my @words = split( / /, $firstline );
> print "$_\n" foreach ( @words );
> 
> 
> $firstline = join( ' ', @words ); # joins the string
> back together and prints it.
> print "$firstline\n";
> 
> 
> __
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com


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



Re: uppercase strings

2003-10-08 Thread Jeff 'japhy' Pinyan
On Oct 8, Sara Gribble said:

>I would appreciate some help with this. I am learning
>Perl. I have a string inputed by the user. This string
>is then split, every first letter of each word in the
>string is uppercased, then joined back together and
>printed.

>my @words = split( / /, $firstline );
>print "$_\n" foreach ( @words );

What you need to do goes here.

There are many ways to make the first character of a string in an array of
strings uppercase.  Here is one way:

  foreach (@words) { $_ = ucfirst }

>$firstline = join( ' ', @words ); # joins the string
>print "$firstline\n";

Read 'perldoc -f ucfirst' for more details.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



uppercase strings

2003-10-08 Thread Sara Gribble
I would appreciate some help with this. I am learning
Perl. I have a string inputed by the user. This string
is then split, every first letter of each word in the
string is uppercased, then joined back together and
printed.

Here is my code, can anyone help? Thanks, Sara G.

!/usr/bin/perl
# Demonstrating split and join when prompting the user
for input and then changing the first letter of each
word in a sentence to uppercase.

use strict;

print "Please enter a sentence of your choice\n";
my $firstline = ;
chomp ( $firstline );

my @words = split( / /, $firstline );
print "$_\n" foreach ( @words );


$firstline = join( ' ', @words ); # joins the string
back together and prints it.
print "$firstline\n";


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Re: Handling Dates Suggestions

2003-10-08 Thread Tore Aursand
On Wed, 08 Oct 2003 17:56:03 -0700, perl wrote:
> Can someone offers some recommendation into using dates?

Take a look at CPAN [1] for Date-related modules.  My personal favorite
has become Time::Piece, although all the Date::* modules should be looked
upon.

[1] http://www.cpan.org/>


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



Re: Exponential numbers

2003-10-08 Thread John W. Krahn
Pedro Antonio Reche wrote:
> 
> I have a table that has exponential numbers of the type 0.203E-2 and I
> will like to reformat getting rid off the exponential so that the
> previous number would look when printed as 0.00203.
> Is there any easy way to do this?
> Any help welcome.

$ perl -le' $x = "0.203E-2"; print $x; print $x + 0 '
0.203E-2
0.00203


John
-- 
use Perl;
program
fulfillment

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




Re: cat \u with a string

2003-10-08 Thread John W. Krahn
Brian Gruber wrote:
> 
> Hello,

Hello,

> In the midst of learning perl, I was messing around with stuff, and I
> found the following behavior to be a bit confusing.  For some reason,
> I seem to be unable to cat a \u or \l for that matter with another
> string using the . operator.  Other backslash-escaped characters
> (tabs, newlines etc.) work fine.  So for example:
> 
> $foo = "\u" . "bar";
> print $foo;  #or even print "$foo";
> 
> Prints "bar" and not "Bar".  on the other hand:
> 
> $foo = "bar";
> print "\u$foo";
> 
> works as expected.  i'm sure there's a good reason for this; could
> someone explain it to me?

The strings are interpolated (evaluated) before the concatenation is
performed.  "\u" becomes "" before the strings are joined together.

$ perl -MO=Deparse -e'print "\u" . "bar"'
print 'bar';
-e syntax OK


John
-- 
use Perl;
program
fulfillment

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



cat \u with a string

2003-10-08 Thread Brian Gruber
Hello,

In the midst of learning perl, I was messing around with stuff, and I
found the following behavior to be a bit confusing.  For some reason,
I seem to be unable to cat a \u or \l for that matter with another
string using the . operator.  Other backslash-escaped characters
(tabs, newlines etc.) work fine.  So for example:

$foo = "\u" . "bar";
print $foo;  #or even print "$foo";

Prints "bar" and not "Bar".  on the other hand:

$foo = "bar";
print "\u$foo";

works as expected.  i'm sure there's a good reason for this; could
someone explain it to me?

/brian

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



Handling Dates Suggestions

2003-10-08 Thread perl
Can someone offers some recommendation into using dates?

I will be referencing year, month,day,hour,min,sec. I will also need to
increment or decrement by hours, days, months and years.

thanks,
-rkl


-
eMail solutions by 
http://www.swanmail.com

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



Re: What is hash randomization in 5.8.1?

2003-10-08 Thread Douglas Hunter
Kevin Old wrote:
Hello everyone,

I've seen several references on the Perl5 Porters mailing list about
Perl 5.8.1's hash randomization.  Can someone explain actually what it
is, why I'd want to use it and how to use it?
The most important bit of the documentation in is in perlsec:

"Perl has never guaranteed any ordering of the hash keys and the
ordering has already changed several times during the lifetime of
Perl 5.  Also, the ordering of hash keys has always been, and con-
tinues to be, affected by the insertion order."
There is more detail concerning hash randomization in perlsec under 
"Algorithmic Complexity Attacs", including a link to here: 
http://www.cs.rice.edu/~scrosby/hash/

I've not seen it discussed on any of the major perl sites, just in the
weekly perl5-porters summary.
That's probably because Perl has never guaranteed the order of hashes.

Thanks,
Your welcome.

Kevin
-- Douglas

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


Re: undefined subroutine

2003-10-08 Thread Dodo
I'm trying to convert so I can use a server that doesn't support PHP, but
I'm giving up. With my limited knowledge I think it's impossible. I was told
that the scripting was all Perl, so conversion should have been easy. But, I
guess there's some C mixed in there as well or maybe some of it is PHP
specific.



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



Exponential numbers

2003-10-08 Thread Pedro Antonio Reche
Dear all,
I have a table that has exponential numbers of the type 0.203E-2 and I 
will like to reformat getting rid off the exponential so that the 
previous number would look when printed as 0.00203.
Is there any easy way to do this?
Any help welcome.
Regards,

Pedro

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


Re: undefined subroutine

2003-10-08 Thread Dodo
I'm trying to convert so I can use a server that doesn't support PHP, but
I'm giving up. With my limited knowledge I think it's impossible. I was told
that the scripting was all Perl, so conversion should have been easy. But, I
guess there's some C mixed in there as well or maybe some of it is PHP
specific.



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



Re: Should loops return a value?

2003-10-08 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, R. Joseph Newton wrote:

[...]
> I'm not fond of this particular construct, but then, I'm not fond of grep,
> either. I'd rather use something called get_all_matching().

Oh, you mean 'gam' ;-)

-- 
Kevin Pfeiffer
International University Bremen


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



Re: undefined subroutine

2003-10-08 Thread Rob Dixon
Jeff 'Japhy' Pinyan wrote:
>
> On Oct 8, Rob Dixon said:
> >
> >Jeff 'Japhy' Pinyan wrote:
> >>
> >>   open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
> >> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
> >
> >  my $fd;
> >  open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';
> >
> >might be a better match? With $fd in place of 'BLAH' in the
> >rest of the code.
>
> Only if he's got a version of Perl that supports that syntax.

True. I think it's been around since 5.0. Do you know?

> >> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));
> >>
> >>   my $content = join "", ;
> >>   # or
> >>   my $content;  { local $/; $content = ; }
> >>   # or
> >>   read(BLAH, my $content, -s BLAH);
> >>   # etc.
> >
> >I'm staying faithful to:
> >
> >  my $content = do {local $/; <$fd>};
>
> Last I checked, that makes TWO copies of the string from <$fd>:  one in
> the do BLOCK, and then it gets copied and returned to $content.  I could
> be wrong, but I think I heard about it on p5p.

That's interesting. You mean there's a temporary internal
scalar in the copy process? It's almost certainly the same
as:

  sub readall {
my $fh = shift;
local $/;
<$fh>;
  }

  my $content = readall \*FH;

when the return value would have to be stacked.

Certainly worth thinking about for Gb files, but
it's ripe for in-line optimisation.

I might check. One day :)

Cheers,

Rob



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



Adding nat to cisco

2003-10-08 Thread Dan Muey
Any one have any experience with adding nat statements to a cisco with Perl?

I'm writing a script to do that from a db run by cron and using Net::Telnet::Cisco 
(which I have yet to install and experiement with)

I just want to make sure I'm doing this right or if there's a better way or ??:

###

for(@{$dbh->selectall_arraryref($qry)}) { 
# do query to mark record as checked so $qry won't get this record again next 
time around
# If it can't be done add that fact to $r so that whoever $r gets emailed to  
will know to look into it
my $cmd;
my($cip,$priprt,$pubport,$proto,$inip,$soip) = @{$_};

if($priprt =~ m/^\d+$/ && $pubprt =~ m/^\d+$/) {
if($proto !~ m/^tcp$ && $proto !~ m/^udp$) { $proto = 'tcp'; }
$cmd = "ip nat inside source static $proto $inip $priprt $soip $pubprt 
extendable";
} else { $cmd = "ip nat inside source static $inip $soip"; }

$r .= "Going to Login and Enable and run -$cmd-\n";

my $ses = Net::Telnet::Cisco->new(Host => $cip);
if($ses) {
if($ses->login($lgn{$cip}{'usr'}, $lgn{$cip}{'pss'})) {
if($ses->enable($lgn{$cip}{'enb'})) {
$r .= "\tEntering Configure terminal: ";
$r .= join('',$ses->cmd('configure terminal'));
$r .= "\n\tEntering command: ";
$r .= join('',$ses->cmd($cmd));
$r .= "\n\tLeaving Configure: ";
$r .= join('',$ses->cmd('exit'));
$r .= "\n\tWriting Memory: ";
$r .= join('',$ses->cmd('write memory'));
$ses->disable;
} else { $r .= "Can not enable: " . $ses->errmsg; }
} else { $r .= "Can not login: " . $ses->errmsg; }
$ses->close;
} else { $r .= "Could not create initial session object to -$cip-\n"; }
$r .= "\n";
}

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



Re: What is hash randomization in 5.8.1?

2003-10-08 Thread Paul Johnson
On Wed, Oct 08, 2003 at 05:05:55PM -0400, Kevin Old wrote:
> Hello everyone,
> 
> I've seen several references on the Perl5 Porters mailing list about
> Perl 5.8.1's hash randomization.  Can someone explain actually what it
> is, why I'd want to use it and how to use it?

Perl has never guaranteed the order of hashes, that is the order in
which the results of keys() or values() or each() will be returned.
However, it has always been the case that the ordering was at least
consistent for a particular version of perl if the hash was populated
consistently.

This knowledge could be expoited to launch a Denial of Service Attack
(Algorithmic Complexity Attack) and so, primarily for security reasons,
the ordering within the hash now really is random, every time you
examine the hash.

You don't need to do anything to get this behaviour.  From 5.8.1 it is
the default behaviour - security should be the default.  You may find
that if you have mistakenly made assumptions about the ordering of
hashes that your programs will start to fail.  This is really a bug in
your program that will need to be fixed.  If this is not an option you
want to pursue you can also turn off the hash randomisation either for a
particular run of your program, or you can completely disable the
behaviour at compile time.

> I've not seen it discussed on any of the major perl sites, just in the
> weekly perl5-porters summary.

For more information perldoc perl581delta.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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



What is hash randomization in 5.8.1?

2003-10-08 Thread Kevin Old
Hello everyone,

I've seen several references on the Perl5 Porters mailing list about
Perl 5.8.1's hash randomization.  Can someone explain actually what it
is, why I'd want to use it and how to use it?

I've not seen it discussed on any of the major perl sites, just in the
weekly perl5-porters summary.

Thanks,
Kevin
-- 
Kevin Old <[EMAIL PROTECTED]>


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



Re: undefined subroutine

2003-10-08 Thread Jeff 'japhy' Pinyan
On Oct 8, Rob Dixon said:

>Jeff 'Japhy' Pinyan wrote:
>>
>>   open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
>> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
>
>  my $fd;
>  open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';
>
>might be a better match? With $fd in place of 'BLAH' in the
>rest of the code.

Only if he's got a version of Perl that supports that syntax.

>> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));
>>
>>   my $content = join "", ;
>>   # or
>>   my $content;  { local $/; $content = ; }
>>   # or
>>   read(BLAH, my $content, -s BLAH);
>>   # etc.
>
>I'm staying faithful to:
>
>  my $content = do {local $/; <$fd>};

Last I checked, that makes TWO copies of the string from <$fd>:  one in
the do BLOCK, and then it gets copied and returned to $content.  I could
be wrong, but I think I heard about it on p5p.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: An extra space?

2003-10-08 Thread John W. Krahn
Michael Weber wrote:
> 
> I am trying to write a mail filter that grabs the output of SpamAssassin
> and drops any messages that score above a certain number of points.
> 
> As I am writing it, I want to see exactly what the perl script is
> getting and outputting.  It's a pretty simple script now, it does no
> filtering at all, yet.  It just grabs the message stream from STDIN,
> copies it to a file and prints it back to STDOUT.
> 
> But, with an extra space prepended to each line after the first one.
> The extra space is in both the saved file and the STDOUT stream.
> 
> I know it's got to be something simple, but what?

perldoc -q spaces

Found in /usr/lib/perl5/5.6.0/pod/perlfaq5.pod
   Why do I get weird spaces when I print an array of lines?

   Saying

   print "@lines\n";

   joins together the elements of [EMAIL PROTECTED]' with a space
   between them.  If [EMAIL PROTECTED]' were `("little", "fluffy",
   "clouds")' then the above statement would print:

   little fluffy clouds

   but if each element of [EMAIL PROTECTED]' was a line of text, ending
   a newline character `("little\n", "fluffy\n", "clouds\n")'
   then it would print:

   little
fluffy
clouds

   If your array contains lines, just print them:

   print @lines;


John
-- 
use Perl;
program
fulfillment

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



An extra space?

2003-10-08 Thread Michael Weber
I am trying to write a mail filter that grabs the output of SpamAssassin
and drops any messages that score above a certain number of points.

As I am writing it, I want to see exactly what the perl script is
getting and outputting.  It's a pretty simple script now, it does no
filtering at all, yet.  It just grabs the message stream from STDIN,
copies it to a file and prints it back to STDOUT.  

But, with an extra space prepended to each line after the first one. 
The extra space is in both the saved file and the STDOUT stream.

I know it's got to be something simple, but what?

Thanx!

-Michael

cat grab.pl
#!/usr/bin/perl -w
# This grabs a copy of the message coming in and prints it to
# STDOUT as well as a file.

@msg = ;
print "@msg";

open(message_file, ">> messages.txt");
print message_file "@msg";
close(message_file);

cat grab.pl | ./grab.pl
#!/usr/bin/perl -w
 # This grabs a copy of the message coming in and prints it to
 # STDOUT as well as a file.

{ The rest of the script is echoed with spaces in front of each line,
just like the two above.}

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



Re: Microsoft Word Creation

2003-10-08 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote:
>
> Quoting Rob Dixon <[EMAIL PROTECTED]>:
>
> > <[EMAIL PROTECTED]> wrote:
> >
> > Hi.
> >
> > A name would be nice...?
> >
> > All of the answers are in the module documentation. The code below shows
> > a lot of the common requirements. Anything else you can fish from the
> > POD.
> >
> > Sean, the author of the module, has written O'Reilly's "RTF Pocket Guide"
> > which I haven't seen but assume is still in print. It will be much more
> > comprehensive than the RTF::Cookbook POD.
> >
> > HTH,
> >
> > Rob
> >
> >
> >
> >   use strict;
> >   use warnings;
> >
> >   use RTF::Writer;
> >
> >   my $rtf = RTF::Writer->new_to_file("demo.rtf");
> >
> >   $rtf->prolog( fonts => ['Times New Roman', 'Courier New'] );
> >
> >   $rtf->print(\'\f0\fs24'); # Default to Font zero (Times) in 12 pt
> >
> >   $rtf->paragraph(
> > \'\sa120',  # 6pt space after paragraph
> > \'\b',  # Bold
> > \'\ul', # Underline
> > "Title");
> >
> >   $rtf->paragraph;  # Blank First Paragraph
> >
> >   $rtf->paragraph(
> > \'\sa120',
> > "First text paragraph.");
> >
> >   $rtf->paragraph(
> > \'\sa120',
> > \'\f1', # Font 1 (Courier)
> > "Second text paragraph in Courier New",
> > \'\line',
> > "with an explicit line break.");
> >
> >   $rtf->paragraph(
> > \'\sa120',
> > "Third text paragraph reverts to default font zero.");
> >
> >   # Most arguments takes measurements in twips (twentieths of a point)
> >   # so \sa120 is a space-after of 6 points
> >   # Font Size takes measurements of half a point, so \fs16 is 8-point
> >   #
> >   $rtf->paragraph(
> > \'\sa120',
> > \'\f1',
> > \'\fs16',   # Font size 8pt
> > "Fourth text paragraph in Courier New 8pt ",
> > "with no explicit line break but extended text ",
> > "to show that automatic line wrapping applies ",
> > "just as in Word."
> > );
> >
> >   $rtf->paragraph(
> > \'\sa120',
> > "Fifth text paragraph.");
> >
> >   $rtf->close;
>
> This method would be perfect unless i had problem with the
> encoding. I want to write greek documents but i cannot.

Something like this may help:

  $rtf->prolog(
fonts => ['Times New Roman', 'Courier New'],
more_default => \'\deflang1253',
  );

which sets the default language to 1253 (Greek).
I can't try it out as I have only English fonts
installed. It's documented in the POD, which you
should really read.

If you're really stuck, try editing the resulting RTF
in WORD, changing the language to Greek, and writing
it as a new RTF file. Then you can see what has been changed.

Can't help you much further.

Rob



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



Re: undefined subroutine

2003-10-08 Thread Rob Dixon
Jeff 'Japhy' Pinyan wrote:
>
> On Oct 8, Dodo said:
>
> >Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
> >line 91.
> >I get the same error for filesize, fclose, explode and include.
>
> That's because none of those are Perl functions.  You need to look at some
> Perl tutorial or beginner's manual so you know what you're doing.
>
> >$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
>
>   open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";

  my $fd;
  open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';

might be a better match? With $fd in place of 'BLAH' in the
rest of the code.

> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));
>
> That can be done in many ways...
>
>   my $content = join "", ;
>   # or
>   my $content;  { local $/; $content = ; }
>   # or
>   read(BLAH, my $content, -s BLAH);
>   # etc.

I'm staying faithful to:

  my $content = do {local $/; <$fd>};

:)

> >fclose($fd);
>
>   close BLAH;
>
> >$lines = explode ("%%",$line);
>
>   my @chunks = split /%%/, $content;
>
> >for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];
>
> I don't know what to tell you here... Perl has nicer for loops than C, so
> you might want to use a Perl loop.

...but even so it looks like it should work as it is.
What exactly is the problem?

> >include ($strMiddleCell);
>
> You probably want require().
>
> But WHY are you converting a PHP program to Perl?  What's the point?

I guess it's a question from a job interview. They're
waiting to see if he comes back and asks :-D

Rob



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



RE: Inplace edit regex fun

2003-10-08 Thread Dan Muey
> qx interpolates variables. by the time $1 gets to perl, it's 
> already gone. 
> try:
> 
> print qx(perl -pi -e 's/^$u:hello:([^:]*):/$u:goodbye:\$1/;' file);
> 

That did it! Thanks a million for pointing that out!

> why not simply:
> 
> [panda]$ perl -pi -e 
> 's/^datax:hello:([^:]*):/datax:goodbye:$1/;' file [panda]$

I have to run it in a script that replaces the data with user input among other things.

So that's one of many tasks needed to be done in a certaibn order for theis script to 
do it's thing.

> 
> david

Thanks Again David!

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



Re: if (-d .....

2003-10-08 Thread Tore Aursand
On Wed, 08 Oct 2003 12:39:40 +0200, Daniel Stellwagen wrote:
> if (-d $file)
> 
> What does it mean, and are there more

Try 'perldoc -f -d'.


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



RE: mapping files

2003-10-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
David Byrne wrote:
> Hello,
> 
> I'm trying to map two files INPUT1 to INPUT2.  I
> believe that I've made a syntax error somewhere
> because I'm not retrieving any ouput; yet I know that
> there are IDs in INPUT2 (via $id2) that exist in
> INPUT1 (via $id_1b).
> 
> Also, is there a general, more efficient, way to map
> files that contain similar identifier strings?
Depending on the size, you can use a hash from one file as a key and then read 
the other file and report using the key if exists, etc to do your print out.  Do it 
all the time when looking for dups.  If any doubt on case of data, then either lc or 
uc the keys to make sure there is a hit.

Wags ;)
> 
> Thank you for any advice,
> David
> 
> foreach $line2 () {
> ($id2,$remainder) = split(/\t/,$line2,2);
> foreach $line1 () {
>   ($id_1a,$id_1b) = split (/\t/,$line1,2);
>   chomp($id_1b);
>   if ($id2 eq $id_1b) {
>   print OUTPUT "$id2\t$id_1a\t$remainder";
>   } else {
>   next;
>   }
> }
> }
> 
> __
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



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



mapping files

2003-10-08 Thread David Byrne
Hello,

I'm trying to map two files INPUT1 to INPUT2.  I
believe that I've made a syntax error somewhere
because I'm not retrieving any ouput; yet I know that
there are IDs in INPUT2 (via $id2) that exist in
INPUT1 (via $id_1b).

Also, is there a general, more efficient, way to map
files that contain similar identifier strings?

Thank you for any advice,
David

foreach $line2 () {
($id2,$remainder) = split(/\t/,$line2,2);
foreach $line1 () {
($id_1a,$id_1b) = split (/\t/,$line1,2);
chomp($id_1b);
if ($id2 eq $id_1b) {
print OUTPUT "$id2\t$id_1a\t$remainder";
} else {
next;
}
}
}

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



RE: Inplace edit regex fun

2003-10-08 Thread david
Dan Muey wrote:

>> First, (.*) is very greedy.  You might want to limit it in
>> some way, possibly with a ? modifier like (.*?), possibly by
>> looking for less than . such as ([^:]*) -- anything but a colon.
>> 
>> Second, the backwack numbers \1 .. \9 are only for the
>> matching portion of a subsitution.  You must use their
>> variable representations, $1 .. $9 in the replacement portion.
>> 
> 
> Thanks for the info Casey:
> Ok I tried doing this:
> 
> 'file' has one line
> datax:hello:2:
>  my $u = 'datax';
>  print qx(perl -pi -e 's/^$u:hello:([^:]*):/$u:goodbye:$1/;' file);

qx interpolates variables. by the time $1 gets to perl, it's already gone. 
try:

print qx(perl -pi -e 's/^$u:hello:([^:]*):/$u:goodbye:\$1/;' file);

why not simply:

[panda]$ perl -pi -e 's/^datax:hello:([^:]*):/datax:goodbye:$1/;' file
[panda]$

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,

goto=>print+eval

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



RE: Inplace edit regex fun

2003-10-08 Thread Dan Muey
> First, (.*) is very greedy.  You might want to limit it in 
> some way, possibly with a ? modifier like (.*?), possibly by 
> looking for less than . such as ([^:]*) -- anything but a colon.
> 
> Second, the backwack numbers \1 .. \9 are only for the 
> matching portion of a subsitution.  You must use their 
> variable representations, $1 .. $9 in the replacement portion.
> 

Thanks for the info Casey:
Ok I tried doing this:

'file' has one line
datax:hello:2:
 my $u = 'datax';
 print qx(perl -pi -e 's/^$u:hello:([^:]*):/$u:goodbye:$1/;' file);
And file changes to:
datax:goodby::
But I get a 'use of uninitialized value (IE about $1)
Same thing with \1 instead of $1 (except I get a space in 
between colons and no error)  so I need a letter after 
the regex or something (e or x or ??)?

I thought I messed up the regex in () but so I did this to rule that out:
 my $u = 'datax';
 print qx(perl -pi -e 's/^$u:hello:(2):/$u:goodbye:$1/;' file);

Same exact result, it still didn't assign $1 or \1 the value of '2'.
What could I be missing?? I'm going crazy!!!
 
Thanks

Dan

>   Casey West
> 
> -- 
> The goal of Computer Science is to build something that will 
> last at least until we've finished building it.

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



Re: undefined subroutine

2003-10-08 Thread Jeff 'japhy' Pinyan
On Oct 8, Dodo said:

>Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
>line 91.
>I get the same error for filesize, fclose, explode and include.

That's because none of those are Perl functions.  You need to look at some
Perl tutorial or beginner's manual so you know what you're doing.

>$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");

  open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";

>$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));

That can be done in many ways...

  my $content = join "", ;
  # or
  my $content;  { local $/; $content = ; }
  # or
  read(BLAH, my $content, -s BLAH);
  # etc.

>fclose($fd);

  close BLAH;

>$lines = explode ("%%",$line);

  my @chunks = split /%%/, $content;

>for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];

I don't know what to tell you here... Perl has nicer for loops than C, so
you might want to use a Perl loop.

>include ($strMiddleCell);

You probably want require().

But WHY are you converting a PHP program to Perl?  What's the point?

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: Inplace edit regex fun

2003-10-08 Thread Casey West
It was Wednesday, October 08, 2003 when Dan Muey took the soap box, saying:
: Howdy list: 
: 
: Trying to do an inplace edit:
: 
: perl -pi -e 's/whatever/newstuff/;' /file/path/here
: 
: What I need to do is replace certain parts of the line for instance:
: 
: 
: s/^$var:(.*):123:def/$var:\1:456:ghi/;

First, (.*) is very greedy.  You might want to limit it in some way,
possibly with a ? modifier like (.*?), possibly by looking for less
than . such as ([^:]*) -- anything but a colon.

Second, the backwack numbers \1 .. \9 are only for the matching
portion of a subsitution.  You must use their variable
representations, $1 .. $9 in the replacement portion.

  Casey West

-- 
The goal of Computer Science is to build something that will last at
least until we've finished building it. 


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



Inplace edit regex fun

2003-10-08 Thread Dan Muey
Howdy list: 

Trying to do an inplace edit:

perl -pi -e 's/whatever/newstuff/;' /file/path/here

What I need to do is replace certain parts of the line for instance:


s/^$var:(.*):123:def/$var:\1:456:ghi/;

Soo if a line matches the $var at the beginning a colon, some stuff, a colon, 123, a 
colon, def 
Replace that with $var, a colon, *whatever was in "some stuff"*, a colon , 456, a 
colon, ghi

It seems like that parens and \1 combo ought to do it but I can't get that to work!
The file does get modified so I have permission it's just that \1 is empty on the 
result and has data before I run the command.

And no I'm not messing with /ets/passwd files :)

I'm runing Perl 5.8 on redhat 9 if that makes a difference. 

TIA

Dan


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



undefined subroutine

2003-10-08 Thread Dodo
I'm doing a php to pl migration and having a little trouble. Help
appreciated!

Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
line 91.
I get the same error for filesize, fclose, explode and include.

$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));
fclose($fd);
$lines = explode ("%%",$line);
for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];

include ($strMiddleCell);



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



Re: required help

2003-10-08 Thread James Edward Gray II
On Tuesday, October 7, 2003, at 11:17  PM, vaishali wrote:

I am sending the email to the [EMAIL PROTECTED] and I am sending to  
you also as this is urgent.
That's why myself and many others read the beginner's list, to fix you  
up as fast as possible.

Using your previous help I can able to solve my problems.
Glad I could help.

sorry.

I am having following code and this prints the report in following  
format

sender: xyz.abc
department: xxx
branch: yyy

receiversent
---
4423432432  2003-09-09 09:09:00
65465466546 2003-08-06 01:10:10
-
Total Cost:
etc

I am having sender,receiver,sent these fields from mysql and  
department and branch it is from text file

the format of text file is

uid:department:branch
xyz.abc:xxx:yyy
I am taking sender field from mysql the format of sender field is
xyz abc <[EMAIL PROTECTED]>
from above I am taking part after < sign and before @ sgin ie xyz.abc
and comparing it with text file. if this found then the program take  
department and branch and prin the report as given in above format.
I'm with you this far.

I want to calculate total cost ie count the receiver and multiply this  
count by Rs.1  ie in above example total receivers are 2 therefore the  
total cost is Rs.2
You lost me right here.  Sorry, I'm not sure what you're trying to  
calculate from what.  Can you give an example?  In the above text, what  
would the total cost equal and what math did you do to get that.  I  
must be dumb today.  :)

how to do this taks in the following code.



#!/usr/bin/perl  -w

$!=1;
This is not needed.  Omit it.

use strict;
use warnings;

use DBI;
#
# Add in your variable names here
#
my $db_name='smsd';
my $db_host='10.100.208.254';
my $db_user='vaishali';
my $db_pass='sms123';
my $table_name='sms_log';
my $file_name='ldap1.txt';
#
# open ldap1 text file and chunk the elements into a hash
open(F,'<'.$file_name) or die "Can't open $file_name: $!\n";
my @file=;
close(F);
my %lp1;
#while(@_=split(/\s+:\s+/,))
#while(@_=split(/\s*:\s*/,))
for my $file (@file) {
 chomp($file);
 my @lp1=(split(/:/,$file));
 $lp1{$lp1[0]}{'uid'}=$lp1[0];
 $lp1{$lp1[0]}{'department'}=$lp1[1];
 $lp1{$lp1[0]}{'branch'}=$lp1[2];
}
undef @file;
I've already shown you a much better way to handle the above file read  
and processing in a previous message.

# Pull the data from the MySQL database
my $dbh=DBI->connect
 ("dbi:mysql:$db_name:$db_host",$db_user,$db_pass)
  or die "Could not connect to $db_name: $DBI::errstr";
my $query=qq~
 SELECT sender,receiver,sent FROM $table_name group by  
sender,receiver,sent~;
my $sth=$dbh->prepare($query);
$sth->execute
  or die "Could not execute to $query: $DBI::errstr";
my %seen=();
my $header=
 ('-' x 58).$/.
 q~receiversent  ~.$/.
 ('-' x 58).$/;
# Now compare MySQL returns to lpad1 set

while (my $row=$sth->fetchrow_arrayref()) {

(my $temp_sender1=$row->[0])=~s/^.*?<|[EMAIL PROTECTED]//g;
(my $temp_sender2=$row->[0])=~s/^.*?<|[EMAIL PROTECTED]//g;
I don't understand what is going on above, but I don't think it's good.  
 Why are we setting to variables to the exact same thing?

if (!$lp1{$temp_sender1}{'department'})
{
Are you trying to test if the entry doesn't exist here?  That would  
probably be better as:

if (not exists $lp1{$temp_sender1}) {

   $lp1{$temp_sender1}{'department'}="";
   $lp1{$temp_sender1}{'branch'}="";
}
print $/,$/,'sender  
:',$temp_sender2,$/,'Department:',$lp1{$temp_sender1}{'department'},$/ 
,'Branch:',$lp1{$temp_sender1}{'branch'},$/,$header  
if(!$seen{$temp_sender2}++);
print $row->[1],(' ' x (28-length($row->[1]))),
  $row->[2],(' ' x (22-length($row->[2]))),$/;
}
I like "\n" better than $/, though that's just a stylistic preference.

Send, back to the list, some details about the calculation you're  
trying to find and I'll try to help you get there.

James

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


Re: standard out returns "nothing", how do I print?

2003-10-08 Thread Jeff 'japhy' Pinyan
On Oct 8, Anthony J Segelhorst said:

>@temparray = `"$lcf_tools\\ntprocinfo |$lcf_tools\\grep $process"`;

Lose the double-quotes.  You want `$lcf_tools\\ntprocinfo ...`.  The
double quotes are probably not helping.

>foreach $temp (@temparray){
>($pid,$name) = split(" ", $temp);
>print LOGFILE "The process named $name is running\n";
>if ($name == ""){

You don't have warnings turned on, so you're not warned that you're using
== with a STRING.  Don't use == and != with strings, use eq and ne.

  if ($name eq "") { ... }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



standard out returns "nothing", how do I print?

2003-10-08 Thread Anthony J Segelhorst
I have the following bit of code I have written:
@temparray = `"$lcf_tools\\ntprocinfo |$lcf_tools\\grep $process"`;
foreach $temp (@temparray){
($pid,$name) = split(" ", $temp);
print LOGFILE "The process named $name is running\n";
if ($name == ""){
print LOGFILE "The process named $process is not 
running\n";
print "WinProcess-$severity-$process-$group";
}
}
}



I am trying to monitor processes using this script, and if i run an 
ntprocinfo |grep asdfkljasdfjk and it returns nothing Ineed to print this 
to standard out.  How can i logically check this.  The return from 
ntprocinfo should return nothing if the process is not running and if it 
is running it will return code.  I can get I get the following logic to 
work?  I basically need to do a print if nothing is returned, this is 
where I am lost.

if ($name == ""){
print LOGFILE "The process named $process is not 
running\n";
print "WinProcess-$severity-$process-$group";






Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [EMAIL PROTECTED]


This email has been scanned for all viruses by the MessageLabs SkyScan
service.___

Note:  Please update your email address for this user to reflect the
new MeadWestvaco Corporation.  MeadWestvaco employee email addresses
are in the format of [EMAIL PROTECTED] 

This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure.  The
information is intended to be used solely by the recipient(s)
named.  If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited.  If you have
received this transmission in error, please notify MeadWestvaco
immediately at [EMAIL PROTECTED]
___

Re: how to reuse sub

2003-10-08 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

> I guess, you're the man!
>
> Your code works. I did not know of the Exporter.
>
> What happens if there are several package with the same name and exported?
>
> thanks,
> rkl

Then you have to prepend the name.  For some reason the term is slipping my
mind, but a sub declared in an immediate scope will hide a similarly named sub
imported from another package.  Methods of the same name imported from more than
one package will compete with each other.  This should cause a compiler error.
I'll see if I have time to test it before I head off to the day job.

Nope.  The last definition read overshadows any previous one.  I modified the
code in MyCommon::do_wrap() to eliminate the single quotes around the return
value, and re-saved the file as MyCommon2.pm, then included both in the
test_my_common.pl.  When MyCommon2 was use'd after MyCommon, the string printed
without quotes, when I reversed the order of inclusion, the single quotes were
back.  The compiler gave no warning or error, just took the most recent
definition.

MyCommon.pm
package MyCommon;

use strict;
use warnings;

use Exporter;

our @ISA = 'Exporter';
our @EXPORT = qw(do_wrap);

sub do_wrap {
my $retval;

if(length($_[0]) == 0) {
  $retval = "null";
} else {
  $retval = "'" . $_[0] . "'";
}
return $retval;
}

1;

MyCommon2.pm:
package MyCommon2;

use strict;
use warnings;

use Exporter;

our @ISA = 'Exporter';
our @EXPORT = qw(do_wrap);

sub do_wrap {
my $retval;

if(length($_[0]) == 0) {
  $retval = "zero-length";
} else {
  $retval = $_[0];
}
return $retval;
}

1;

test_my_common.pl:
#!perl

use strict;
use warnings;

use MyCommon2;
use MyCommon;

my $return = do_wrap('hello');
print "$return\n";
$return = MyCommon2::do_wrap('hello');
print "$return\n";

Command Line testing:
Greetings! E:\d_drive\perlStuff>test_my_common.pl
'hello'
hello

Greetings! E:\d_drive\perlStuff>

Joseph


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



Re: Microsoft Word Creation

2003-10-08 Thread sc00170
This method would be perfect unless i had problem with the encoding. I want to 
write greek documents but i cannot.


Quoting Rob Dixon <[EMAIL PROTECTED]>:

> <[EMAIL PROTECTED]> wrote:
> >
> > Quoting Rob Dixon <[EMAIL PROTECTED]>:
> >
> > > John wrote:
> > > >
> > > > Rob Dixon wrote:
> > > > >
> > > > > John wrote:
> > > > > >
> > > > > > I want to create a doc file that will contain my text,
> > > > > > fonts, sizes as if i wrote manually.
> > > > >
> > > > > You can use Win32::OLE drive MSWord itself to generate a document,
> > > > > but I think that's an awful way to do things. Why not look at
> > > > > RTF::Generator which will let you create an RTF file which Word
> > > > > will then read happily.
> > > >
> > > > > My apologies, that should have been RTF::Writer.
> > > >
> > > > Have you got any relevant code?
> > >
> > > Hi John.
> > >
> > > Something like this?
> > >
> > >   use strict;
> > >   use warnings;
> > >
> > >   use RTF::Writer;
> > >
> > >   my $rtf = RTF::Writer->new_to_file("demo.rtf");
> > >
> > >   $rtf->prolog;
> > >
> > >   $rtf->paragraph(
> > > \'\b',  # Bold
> > > \'\ul', # Underline
> > > "Title");
> > >
> > >   $rtf->paragraph;  # Blank First Paragraph
> > >
> > >   $rtf->paragraph(
> > > "First text paragraph.");
> > >
> > >   $rtf->paragraph(
> > > "Second text paragraph", \'\line',
> > > "with an explicit line break.");
> > >
> > >   $rtf->close;
> > >
> > > But you'll be better informed by reading the RTF::Writer POD
> > > which includes an RTF primer called RTF::Cookbook.
> > >
> >
> > Your solution is also amazing but where can i define the TrueType fonts
> for
> > every single word? Or the size of them, color,...
> 
> Hi.
> 
> A name would be nice...?
> 
> All of the answers are in the module documentation. The code below shows
> a lot of the common requirements. Anything else you can fish from the
> POD.
> 
> Sean, the author of the module, has written O'Reilly's "RTF Pocket Guide"
> which I haven't seen but assume is still in print. It will be much more
> comprehensive than the RTF::Cookbook POD.
> 
> HTH,
> 
> Rob
> 
> 
> 
>   use strict;
>   use warnings;
> 
>   use RTF::Writer;
> 
>   my $rtf = RTF::Writer->new_to_file("demo.rtf");
> 
>   $rtf->prolog( fonts => ['Times New Roman', 'Courier New'] );
> 
>   $rtf->print(\'\f0\fs24'); # Default to Font zero (Times) in 12 pt
> 
>   $rtf->paragraph(
> \'\sa120',  # 6pt space after paragraph
> \'\b',  # Bold
> \'\ul', # Underline
> "Title");
> 
>   $rtf->paragraph;  # Blank First Paragraph
> 
>   $rtf->paragraph(
> \'\sa120',
> "First text paragraph.");
> 
>   $rtf->paragraph(
> \'\sa120',
> \'\f1', # Font 1 (Courier)
> "Second text paragraph in Courier New",
> \'\line',
> "with an explicit line break.");
> 
>   $rtf->paragraph(
> \'\sa120',
> "Third text paragraph reverts to default font zero.");
> 
>   # Most arguments takes measurements in twips (twentieths of a point)
>   # so \sa120 is a space-after of 6 points
>   # Font Size takes measurements of half a point, so \fs16 is 8-point
>   #
>   $rtf->paragraph(
> \'\sa120',
> \'\f1',
> \'\fs16',   # Font size 8pt
> "Fourth text paragraph in Courier New 8pt ",
> "with no explicit line break but extended text ",
> "to show that automatic line wrapping applies ",
> "just as in Word."
> );
> 
>   $rtf->paragraph(
> \'\sa120',
> "Fifth text paragraph.");
> 
>   $rtf->close;
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 




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



Re: Best Token Char For Template

2003-10-08 Thread Paul Johnson
On Wed, Oct 08, 2003 at 02:44:11PM +0200, Jenda Krynicky wrote:
> From: "Rob Dixon" <[EMAIL PROTECTED]>
> > <[EMAIL PROTECTED]> wrote:
> > >
> > > 1 - What is the best char to use in a file template?
> > > Also, please give me a good regex?
> > >
> > > I will have a formatted html page with some keys that I want to
> > > replace.
> > 
> > Your substitution is fine, just add a /g to it to change all tags in
> > the string instead of just the first. Like this
> > 
> >   $line =~ s//$fname/g;
> > 
> > Unless you have a good reason to read in the whole file at once,
> > process it a record at a time.
> 
> Of course keep in mind that your tokens cannot span several lines 
> then:
> 
>   
> 
> would not work.

Also, keep in mind that there are a multitude of CPAN modules that will
do this for you.  If you choose wisely you will have a solution that
grows with your needs, even though you might not think your needs will
grow.

Off the top of my head, I think that the most popular modules will be
Template Toolkit, Mason, HTML::Template and Text::Template.

This is a wheel that really isn't worth reinventing.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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



Re: Best Token Char For Template

2003-10-08 Thread Jenda Krynicky
From: "Rob Dixon" <[EMAIL PROTECTED]>
> Nobody else has mentioned this, but I think it's nice to have a name
> to write to. '[EMAIL PROTECTED]' and 'rkl' don't do a lot for me!

Agreed completely.
 
> <[EMAIL PROTECTED]> wrote:
> >
> > 1 - What is the best char to use in a file template?
> > Also, please give me a good regex?
> >
> > I will have a formatted html page with some keys that I want to
> > replace.
> >
> > For example,
> >
> > ...
> > 
> > First Name:!fname!
> > Last Name:~!lname!
> > ...
> 
> Unless there's a good reason not to, I would use an HTML comment tag
> 
>   
> 
>   
> 
> etc. so that the HTML parses OK before the subtitutions are done.

Well ... I like to be able to see the things I forgot to replace.

I usualy use
[% name %]
for things that are to be replaced.

> > 2 - Can I read in the whole page and do a replacement?
> > I'm thinking it's either a line-by-line or a whole page as below:
> >
> > #line-by-line replace token
> > $line ~= s/!fname!/$fname/
> >
> > #or put the whole template in
> > $page ~= s/!fname!/$fname/
> > $page ~= s/!lname!/$lname/
> 
> 
> Your substitution is fine, just add a /g to it to change all tags in
> the string instead of just the first. Like this
> 
>   $line =~ s//$fname/g;
> 
> Unless you have a good reason to read in the whole file at once,
> process it a record at a time.

Of course keep in mind that your tokens cannot span several lines 
then:



would not work.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



threads in perl

2003-10-08 Thread Igor Ryaboy
Hi,
I need help in simple threaded solution.
How can I join the active thread?

After I was started the thread I want him to join itself at the end and go back to the 
main
Example:

# main program
$thr1=new threads \&sub_name;
$thr2=new threads \&sub_name;
$thr3=new threads \&sub_name;
$thr4=new threads \&sub_name;

# threaded subroutine
sub sub_name{
print ("\nIn the thread!\n");
# here I need help to join this thread after theprint

}

I need that every started thread will be killed after finished and thread->list to be 
updated


Thank you all,
Igor 
Please email me to [EMAIL PROTECTED]

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



RE: if (-d .....

2003-10-08 Thread Daniel Stellwagen
Thank you Stephan :-)

> 
> This will return 'true' is $file contains the location of a 
> directory. More information can be found on this in the 
> 'perlfunc' manpage in the 'Alphabetical Listing of Perl 
> Functions' section.


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



Re: Chopping off first&last character in a string

2003-10-08 Thread Rob Dixon

William Li wrote:
>
> Silly question, is there an equal but opposite function to chop in Perl?
> I'd like to remove the first and last character of a string and am looking
> for a simple way to do it.  So far I have:
>
> # "1234567" -> "23456"
> chop($string); # "123456"
> $string = reverse($string); # "654321"
> chop($string); # "65432"
> $string = reverse($string); # "23456"

Hi.

To resolve the problem, I ran the benchmark below and got these results:

Benchmark: timing 1000 iterations of Control, One Substitute, One Substring, Two 
Substitutes, Two Substrings...
   Control: 25 wallclock secs (25.43 usr +  0.00 sys = 25.43 CPU) @ 393236.34/s 
(n=1000)
One Substitute: 112 wallclock secs (111.50 usr +  0.00 sys = 111.50 CPU) @ 89686.10/s 
(n=1000)
One Substring: 54 wallclock secs (53.28 usr +  0.00 sys = 53.28 CPU) @ 187687.69/s 
(n=1000)
Two Substitutes: 62 wallclock secs (62.12 usr +  0.00 sys = 62.12 CPU) @ 160978.75/s 
(n=1000)
Two Substrings: 57 wallclock secs (57.57 usr +  0.00 sys = 57.57 CPU) @ 173701.58/s 
(n=1000)

Subtracting the control time from the four options gives

One Substitute: 87 secs
One Substring: 29 secs
Two Substitutes: 37 secs
Two Substrings: 32 secs

So the fastest by a nose is Tore's

  $string = substr( $string, 1, (length($string) - 2) )

although the three fastest are remarkably similar. As predicted James'
single substitution

  $string =~ s/^.(.*).$/$1/;

was by far the slowest, but by just three times rather than the 20+ times
that Rob H had predicted.

Cheers,

Rob



  use strict;
  use warnings;

  use Benchmark;

  timethese(10E6, {

  'Control' => sub {
my $str = join '', 'A' .. 'Z';
  },

  'Two Substitutes' => sub {
my $str = join '', 'A' .. 'Z';
for ($str) {
  s/^.//s;
  s/.$//s;
}
  },

  'One Substitute' => sub {
my $str = join '', 'A' .. 'Z';
for ($str) {
  s/^.(.*).$/$1/s;
}
  },

  'Two Substrings' => sub {
my $str = join '', 'A' .. 'Z';
for ($str) {
  substr($_, 0, 1, '');
  substr($_, -1, 1, '');
}
  },

  'One Substring' => sub {
my $str = join '', 'A' .. 'Z';
for ($str) {
  $_ = substr ($_, 1, (length($str) - 2) );
}
  },
  });



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



RE: if (-d .....

2003-10-08 Thread Stephen Hardisty
> Hi EVERYBODY,

Hi Dr Nick

> 
> i saw this "-d" switch in an "if" statement.
> 
> if (-d $file)
> 
> What does it mean, and are there more
> this kind of switches and where can I find information about them.

This will return 'true' is $file contains the location of a directory. More 
information can be found on this in the 'perlfunc' manpage in the 'Alphabetical 
Listing of Perl Functions' section.


This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com


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



if (-d .....

2003-10-08 Thread Daniel Stellwagen
Hi EVERYBODY,

i saw this "-d" switch in an "if" statement.

if (-d $file)

What does it mean, and are there more
this kind of switches and where can I find information about them.


Thanks

d a n i e l


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



Re: regex, is this possible?

2003-10-08 Thread Sudarshan Raghavan
Jerry Preston wrote:

> Hi!
> 
> I am trying to break down the following:
> 
>printf("numsteps=%d  i=%d im=%g vfr=%g \n",numsteps,i,imeas,vforce);
> into
>"numsteps= numsteps  i=i im=imeas vfr=vforce \n"
> 
>printf ("\noriginal cap = %g, offset = %g", *ci, cap_offset);
> into
>"\noriginal cap = ci, offset = cap_offset";
> 
> I am wanting to improve my limited regex skills.  Is the above possible or
> is there a better way with one method?

This can be done using regexes, there might be better methods out there 
that I am not aware of. I guess this should get you started.

Note: I have not tested this for all scenarios and this will require you to 
do some more work. The obvious one being, handling spaces.

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

while () {
chomp;

#Remove unwanted chars at the beginning
my $format_str = $1 if (s/^printf\(?"(.*)",?//);
next unless (defined ($format_str));
#Remove unwanted chars at the end
s/\)?;//;
#Get the parameters list
my @params = split (',');

$format_str=~ s/\%\w/shift (@params)/ge;
print $format_str, "\n";
}

__DATA__
printf("Hello World");
printf("a=%d b=%f c=%r\n", a, b, c);
printf("a=%d\n", a, b);
printf("numsteps=%d  i=%d im=%g vfr=%g \n",numsteps,i,imeas,vforce);
printf("\noriginal cap = %g, offset = %g", *ci, cap_offset);
printf("");


Output
Hello World
a= a b= b c= c\n
a= a\n
numsteps=numsteps  i=i im=imeas vfr=vforce \n
\noriginal cap =  *ci, offset =  cap_offset


> 
> Thanks,
> 
> Jerry


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



RE: regex, is this possible?

2003-10-08 Thread Thomas Bätzler
Jerry Preston <[EMAIL PROTECTED]> asked:
> I am trying to break down the following:
> 
>printf("numsteps=%d  i=%d im=%g vfr=%g 
> \n",numsteps,i,imeas,vforce);
> into
>"numsteps= numsteps  i=i im=imeas vfr=vforce \n"
> 
>printf ("\noriginal cap = %g, offset = %g", *ci, cap_offset);
> into
>"\noriginal cap = ci, offset = cap_offset";
> 
> I am wanting to improve my limited regex skills.  Is the 
> above possible or
> is there a better way with one method?

Off the top of my head:

s/printf\s*\(\*(".*?").*?\);/$1;/g

Anchoring the end of the pattern with ");" should
insure you against mismatches when there is a
function call instead of a variable in the argument
list. Still, the pattern fails for weird templates
like

printf("some \"quoted\" text" ();", foo, baz, bar );

If you want to have a bullet-prrof solution, you
should check out Text::Balanced, which takes care of
stuff like balanced quotes, brackets and such.

HTH,
Thomas

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



Re: Best Token Char For Template

2003-10-08 Thread Rob Dixon
Hi.

Nobody else has mentioned this, but I think it's nice to have a name
to write to. '[EMAIL PROTECTED]' and 'rkl' don't do a lot for me!

<[EMAIL PROTECTED]> wrote:
>
> 1 - What is the best char to use in a file template?
> Also, please give me a good regex?
>
> I will have a formatted html page with some keys that I want to replace.
>
> For example,
>
> ...
> 
> First Name:!fname!
> Last Name:~!lname!
> ...

Unless there's a good reason not to, I would use an HTML comment tag

  

  

etc. so that the HTML parses OK before the subtitutions are done.

> 2 - Can I read in the whole page and do a replacement?
> I'm thinking it's either a line-by-line or a whole page as below:
>
> #line-by-line replace token
> $line ~= s/!fname!/$fname/
>
> #or put the whole template in
> $page ~= s/!fname!/$fname/
> $page ~= s/!lname!/$lname/


Your substitution is fine, just add a /g to it to change all tags
in the string instead of just the first. Like this

  $line =~ s//$fname/g;

Unless you have a good reason to read in the whole file at once,
process it a record at a time. Like this:

  use strict;
  use warnings;

  open IN, 'template.htm' or die $!;

  my %values = ( fname => 'Rob', lname => 'Dixon' );

  while () {
s//$values{fname}/g;
s//$values{lname}/g;
print;
  }

  close IN;

I hope that helps.

Rob



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



Re: Microsoft Word Creation

2003-10-08 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote:
>
> Quoting Rob Dixon <[EMAIL PROTECTED]>:
>
> > John wrote:
> > >
> > > Rob Dixon wrote:
> > > >
> > > > John wrote:
> > > > >
> > > > > I want to create a doc file that will contain my text,
> > > > > fonts, sizes as if i wrote manually.
> > > >
> > > > You can use Win32::OLE drive MSWord itself to generate a document,
> > > > but I think that's an awful way to do things. Why not look at
> > > > RTF::Generator which will let you create an RTF file which Word
> > > > will then read happily.
> > >
> > > > My apologies, that should have been RTF::Writer.
> > >
> > > Have you got any relevant code?
> >
> > Hi John.
> >
> > Something like this?
> >
> >   use strict;
> >   use warnings;
> >
> >   use RTF::Writer;
> >
> >   my $rtf = RTF::Writer->new_to_file("demo.rtf");
> >
> >   $rtf->prolog;
> >
> >   $rtf->paragraph(
> > \'\b',  # Bold
> > \'\ul', # Underline
> > "Title");
> >
> >   $rtf->paragraph;  # Blank First Paragraph
> >
> >   $rtf->paragraph(
> > "First text paragraph.");
> >
> >   $rtf->paragraph(
> > "Second text paragraph", \'\line',
> > "with an explicit line break.");
> >
> >   $rtf->close;
> >
> > But you'll be better informed by reading the RTF::Writer POD
> > which includes an RTF primer called RTF::Cookbook.
> >
>
> Your solution is also amazing but where can i define the TrueType fonts for
> every single word? Or the size of them, color,...

Hi.

A name would be nice...?

All of the answers are in the module documentation. The code below shows
a lot of the common requirements. Anything else you can fish from the
POD.

Sean, the author of the module, has written O'Reilly's "RTF Pocket Guide"
which I haven't seen but assume is still in print. It will be much more
comprehensive than the RTF::Cookbook POD.

HTH,

Rob



  use strict;
  use warnings;

  use RTF::Writer;

  my $rtf = RTF::Writer->new_to_file("demo.rtf");

  $rtf->prolog( fonts => ['Times New Roman', 'Courier New'] );

  $rtf->print(\'\f0\fs24'); # Default to Font zero (Times) in 12 pt

  $rtf->paragraph(
\'\sa120',  # 6pt space after paragraph
\'\b',  # Bold
\'\ul', # Underline
"Title");

  $rtf->paragraph;  # Blank First Paragraph

  $rtf->paragraph(
\'\sa120',
"First text paragraph.");

  $rtf->paragraph(
\'\sa120',
\'\f1', # Font 1 (Courier)
"Second text paragraph in Courier New",
\'\line',
"with an explicit line break.");

  $rtf->paragraph(
\'\sa120',
"Third text paragraph reverts to default font zero.");

  # Most arguments takes measurements in twips (twentieths of a point)
  # so \sa120 is a space-after of 6 points
  # Font Size takes measurements of half a point, so \fs16 is 8-point
  #
  $rtf->paragraph(
\'\sa120',
\'\f1',
\'\fs16',   # Font size 8pt
"Fourth text paragraph in Courier New 8pt ",
"with no explicit line break but extended text ",
"to show that automatic line wrapping applies ",
"just as in Word."
);

  $rtf->paragraph(
\'\sa120',
"Fifth text paragraph.");

  $rtf->close;



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



regex, is this possible?

2003-10-08 Thread Jerry Preston
Hi!

I am trying to break down the following:

   printf("numsteps=%d  i=%d im=%g vfr=%g \n",numsteps,i,imeas,vforce);
into
   "numsteps= numsteps  i=i im=imeas vfr=vforce \n"

   printf ("\noriginal cap = %g, offset = %g", *ci, cap_offset);
into
   "\noriginal cap = ci, offset = cap_offset";

I am wanting to improve my limited regex skills.  Is the above possible or
is there a better way with one method?

Thanks,

Jerry
  

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

Re: how to reuse sub

2003-10-08 Thread perl
I guess, you're the man!

Your code works. I did not know of the Exporter.

What happens if there are several package with the same name and exported?

thanks,
rkl

> [EMAIL PROTECTED] wrote:
>
>> > my $return = do_wrap('hello');
>>
>> Doesn't this have to be MyCommon::do_wrap('hello'); ?
>
> No.  You do not have to prepend the package name when Exporter is properly
> invoked.  That proper invocation can be a bit tricky, though.  That is why
> it
> sat for a few days, while I worked on other projects.
>
>> When running it, the error: Undefined subroutine &main::do_wrap
>>
>> thanks,
>> -rkl
>
> What Perl version are you using?  Did you test the code exactly as posted?
>  I
> put a bit of time into making this work.  Could you show us the code as
> you
> ranit, and the results from the command-line?
>
> What I showed at the end was my test run, using Perl 5.8.0. from the
> Windows
> 2000 command line.
>
> Joseph
>
>



-
eMail solutions by 
http://www.swanmail.com

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



Re: Microsoft Word Creation

2003-10-08 Thread sc00170
Your solution is also amazing but where can i define the TrueType fonts for 
every single word? Or the size of them, color,...

Quoting Rob Dixon <[EMAIL PROTECTED]>:

> John wrote:
> >
> > Rob Dixon wrote:
> > >
> > > John wrote:
> > > >
> > > > I want to create a doc file that will contain my text,
> > > > fonts, sizes as if i wrote manually.
> > >
> > > You can use Win32::OLE drive MSWord itself to generate a document,
> > > but I think that's an awful way to do things. Why not look at
> > > RTF::Generator which will let you create an RTF file which Word
> > > will then read happily.
> >
> > > My apologies, that should have been RTF::Writer.
> >
> > Have you got any relevant code?
> 
> Hi John.
> 
> Something like this?
> 
>   use strict;
>   use warnings;
> 
>   use RTF::Writer;
> 
>   my $rtf = RTF::Writer->new_to_file("demo.rtf");
> 
>   $rtf->prolog;
> 
>   $rtf->paragraph(
> \'\b',  # Bold
> \'\ul', # Underline
> "Title");
> 
>   $rtf->paragraph;  # Blank First Paragraph
> 
>   $rtf->paragraph(
> "First text paragraph.");
> 
>   $rtf->paragraph(
> "Second text paragraph", \'\line',
> "with an explicit line break.");
> 
>   $rtf->close;
> 
> But you'll be better informed by reading the RTF::Writer POD
> which includes an RTF primer called RTF::Cookbook.
> 
> HTH,
> 
> Rob
> 
> 
> 
> -- 
> 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]