comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
May 2008
motuwethfrsasuw
   1234 18
567891011 19
12131415161718 20
19202122232425 21
262728293031  22
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  FAQ 6.8 How can I quote a variable to use in a regex?         


Author: PerlFAQ Server
Date: May 27, 2008 18:03

This is an excerpt from the latest version perlfaq6.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

6.8: How can I quote a variable to use in a regex?

The Perl parser will expand $variable and @variable references in
regular expressions unless the delimiter is a single quote. Remember,
too, that the right-hand side of a "s///" substitution is considered a
double-quoted string (see perlop for more details). Remember also that
any regex special characters will be acted on unless you precede the
substitution with \Q. Here's an example:

$string = "Placido P. Octopus";
$regex = "P.";

$string =~ s/$regex/Polyp/;
# $string is now "Polypacido P. Octopus"
Show full article (2.13Kb)
no comments
  FAQ 6.9 What is "/o" really for?         


Author: PerlFAQ Server
Date: May 27, 2008 12:03

This is an excerpt from the latest version perlfaq6.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

6.9: What is "/o" really for?

(contributed by brian d foy)

The "/o" option for regular expressions (documented in perlop and
perlreref) tells Perl to compile the regular expression only once. This
is only useful when the pattern contains a variable. Perls 5.6 and later
handle this automatically if the pattern does not change.

Since the match operator "m//", the substitution operator "s///", and
the regular expression quoting operator "qr//" are double-quotish
constructs, you can interpolate variables into the pattern. See the
answer to "How can I quote a variable to use in a regex?" for more
details.

This example takes a regular expression from the argument list and
prints the lines of input that match it:
Show full article (3.43Kb)
no comments
  How do I handle an unknown number of keys to hash?         


Author: grocery_stocker
Date: May 27, 2008 09:24

Given

#!/usr/bin/perl -w

my %%ages = ('a' => 1, 'b' => 1, 'c' => 1);

Sometimes 'c' will appear in the list, but other times it won't. Ie
sometimes I'll get

%%ages = ('a' => 1, 'b' => 1);

This becomes an issue when I try to extract 'c' later on.

#!/usr/bin/perl -w

my %%ages = ('a' => 1, 'b' => 1);

print $ages{'c'}, "\n";

/or.pl
Use of uninitialized value in print at ./or.pl line 5.

When this happens, this should print out NULL;

I was thinking about filling %%ages with a bunch of 'undef'=>1. Ideas?
11 Comments
  Win32 OLE Excel existing         


Author: Slickuser
Date: May 27, 2008 08:57

Is there a way to check if Excel exist beside checking the full path
of Excel or use use Win32::OLE::Const 'Microsoft Excel'?

Also, is there a way to tell which Excel they are using such as Office
2003 (11) or Office 2007 (12)?

Thanks.
1 Comment
  FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?         


Author: PerlFAQ Server
Date: May 27, 2008 06:03

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?

Whoops! You just put a tab and a formfeed into that filename! Remember
that within double quoted strings ("like\this"), the backslash is an
escape character. The full list of these is in "Quote and Quote-like
Operators" in perlop. Unsurprisingly, you don't have a file called
"c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy
DOS filesystem.

Either single-quote your strings, or (preferably) use forward slashes.
Since all DOS and Windows versions since something like MS-DOS 2.0 or so
have treated "/" and "\" the same in a path, you might as well use the
one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++,
awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more
portable, too.
Show full article (1.84Kb)
no comments
  disjoint copy one hash to another         


Author: ram
Date: May 27, 2008 03:04

When I create a copy of a hash array, the operation on the copy hash
seems to affect the original hash
( when the values are reference elements )

How do I avoid this ?

In the following script %%y is a copy hash , but change that and the %%x
original hash is affected

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

my %%x = ( a => [1]);
foreach my $i( 1 .. 5){
my %%y = %%x;
push @{$y{a}},5;
print "[Loop $i] " . join(" ",@{$x{a}}) ."\n"; # I want
this to be same in every loop
}
----------------
Show full article (0.85Kb)
3 Comments
  FAQ 5.32 How do I do a "tail -f" in perl?         


Author: PerlFAQ Server
Date: May 27, 2008 00:03

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.32: How do I do a "tail -f" in perl?

First try

seek(GWFILE, 0, 1);

The statement "seek(GWFILE, 0, 1)" doesn't change the current position,
but it does clear the end-of-file condition on the handle, so that the
next "" makes Perl try again to read something.

If that doesn't work (it relies on features of your stdio
implementation), then you need something more like this:
Show full article (1.91Kb)
no comments