|
|
Up |
|
|
  |
Author: tadmctadmc
Date: May 15, 2008 23:11
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information ...
|
| Show full article (16.63Kb) |
|
| |
no comments
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: May 15, 2008 18:03
This is an excerpt from the latest version perlfaq4.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 .
--------------------------------------------------------------------
4.35: How do I find the soundex value of a string?
(contributed by brian d foy)
You can use the Text::Soundex module. If you want to do fuzzy or close
matching, you might also try the "String::Approx", and
"Text::Metaphone", and "Text::DoubleMetaphone" modules.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
|
| Show full article (1.25Kb) |
|
| |
no comments
|
|
  |
Author: kroneckerkronecker
Date: May 15, 2008 17:38
I create a text file on the server remote.txt ok with the following
code (the last part of it)
$first_name = $FORM{command1};
$last_name = $FORM{command2};
open (example, ">remote.txt") || die ("Could not open file. $!");
print example "$first_name\n$last_name\n";
close (example);
print "Content-type:text/html\r\n\r\n";
This bit causes errors...... chmod
0777,'remote.txt'; ......................................
print "";
print "";
print " Processed";
print "";
print "";
print "Commands $first_name $last_name - Sent to text file";
print "";
print "";
|
| Show full article (0.91Kb) |
|
2 Comments |
|
  |
Author: chaddachadda
Date: May 15, 2008 13:27
I 'll eventually have the input file filled with 350 million items.
Right now there is only one
$more input
3308191
The following program reads in the number from the file named 'input'
and builds a url form this number. Then it builds a url from this
number. I have lynx then dump the data into a file called 'out' and
then just grep the entire thing for the Product Number, Product ID,
SKU, UPC, and weight.
m-net%% more parse.pl
#!/usr/bin/perl -w
my (@shit, $read, $build, @product, @id, @sku, @upc, @weight);
my $temp;
|
| Show full article (1.29Kb) |
|
37 Comments |
|
  |
Author: slnsln
Date: May 15, 2008 12:40
ActiveState perl guidelines state its better to pass by reference for best performance.
Does this apply in the case of SCALARS?
It would seem that dereferencing a SCALAR reference would create a temporary of the original
and I think this is the case.
Perl seems to know array and hash references pretty well and, internally, dereferencing them does
not seem to incur overhead of making a temporary copy of the original array or hash, the element is
directly accessed, as if the reference were a pointer.
Thats fine, I have no problem at all with this. I am only interrested in SCALAR.
I was curious about the function 'substr'. The first parameter is EXPRESSION. It seems to be an
EXPRESSION evaluator. On its face, it will not take a reference, but it will take a dereferenced SCALAR.
But I wonder if, based on the EXPRESSION, if it knows it is dereferencing a SCALAR, and does not make a temporary copy.
In the case of the regular expression engine, I wonder the same thing, although with this there may be other properties
that would cause the discrepancies shown below.
For example 'pos()=' and '= pos()' might incur much overhead, and that may explain it as it could produce unknown temporaries
in the engine.
If I run this code segment 100 times, the substr is averaging 10 times faster than the regex. I can't explain it.
Thanks!
// substr
return substr($$refscalar, 20, 30);
|
| Show full article (1.54Kb) |
|
5 Comments |
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: May 15, 2008 12:03
This is an excerpt from the latest version perlfaq4.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 .
--------------------------------------------------------------------
4.43: How do I compute the difference of two arrays? How do I compute the intersection of two arrays?
Use a hash. Here's code to do both and more. It assumes that each
element is unique in a given array:
@union = @intersection = @difference = ();
%%count = ();
foreach $element (@array1, @array2) { $count{$element}++ }
foreach $element (keys %%count) {
push @union, $element;
push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
}
Note that this is the *symmetric difference*, that is, all elements in
either A or in B but not in both. Think of it as an xor operation.
--------------------------------------------------------------------
|
| Show full article (1.69Kb) |
|
no comments
|
|
  |
Author: OrsonOrson
Date: May 15, 2008 11:48
Sorry, this is probably silly question, but I cannot find right
answer.
I am trying to use grep -P (for perl regular expressions). I want to
match lines that do not contain the chars "sync".
I thought I could do:
grep -P "[^(sync)]" mytextfile
I understand [] matches any char in the brackets and (sync) groups
those chars together, so I would negate to mean should not match those
chars.
This is return all lines in the file. I am doing something wrong, just
do not know what. Can someone explain, please?
|
| |
|
7 Comments |
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: May 15, 2008 06:03
This is an excerpt from the latest version perlfaq4.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 .
--------------------------------------------------------------------
4.44: How do I test whether two arrays or hashes are equal?
The following code works for single-level arrays. It uses a stringwise
comparison, and does not distinguish defined versus undefined empty
strings. Modify if you have other needs.
$are_equal = compare_arrays(\@frogs, \@toads);
|
| Show full article (2.81Kb) |
|
no comments
|
|
  |
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: May 15, 2008 00:03
This is an excerpt from the latest version perlfaq4.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 .
--------------------------------------------------------------------
4.49: How do I process/modify each element of an array?
Use "for"/"foreach":
for (@lines) {
s/foo/bar/; # change that word
tr/XZ/ZX/; # swap those letters
}
Here's another; let's compute spherical volumes:
for (@volumes = @radii) { # @volumes has changed parts
$_ **= 3;
$_ *= (4/3) * 3.14159; # this will be constant folded
}
which can also be done with "map()" which is made to transform one list
into another:
|
| Show full article (2.18Kb) |
|
no comments
|
|
|
|
|