perl

How are Perl's core libraries managed?

From my understanding Perl traditionally has only included core functionality, and people install additional libraries to do all sorts of useful (and sometimes very basic) things. But at some point there came to be "core libraries" which are shipped with Perl by default – so you can use these libraries without installing them. Coming f...

Perl, evaluate string lazily

Consider the following Perl code. #!/usr/bin/perl use strict; use warnings; $b="1"; my $a="${b}"; $b="2"; print $a; The script obviously outputs 1. I would like it to be whatever the current value of $b is. What would be the smartest way in Perl to achieve lazy evaluation like this? I would like the ${b} to remain "unreplaced" ...

Reading Web 2.0 HTML Source Code with Perl

Is it possible to read HTML Web 2.0 Source Code that is dynamically generated ? The Perl LWP with its agent->response does not pick up any dynamically generated HTML code. Many websites today are generating dynamic html. If I am shoppping for best prices, and the prices are dynamically fetched and dumped, then I am out of business. Are...

How to include Perl into shtml files

Hi I am trying to include a perl script within my shtml file. Unfortunately when I do my script doesnt seem to run but instead it just displays the content of the script. The code I am using is as follows: test.shtml: <html> <title> business home page </title> <body> </br> <!--#echo var="DATE_LOCAL" --> <br /> <!--#include virtual="h...

Perl replace slash in variable

How can I replace the slash inside the variable? $string = 'a\cc\ee'; $re = 'a\\cc'; $rep = "Work"; #doesnt work in variable $string =~ s/$re/$rep/og; print $string."\n"; #work with String $string =~ s/a\\cc/$rep/og; print $string."\n"; output: a\cc\ee Work\ee ...

Perl, dereference array of references

In the following Perl code, I would expect to be referencing an array reference inside an array #!/usr/bin/perl use strict; use warnings; my @a=([1,2],[3,4]); my @b = @$a[0]; print $b[0]; However it doesn't seem to work. I would expect it to output 1. @a is an array of references @b is $a[1] dereferenced (I think) So what's the...

Perl Hash Slice, Replication x Operator, and sub params

Ok, I understand perl hash slices, and the "x" operator in Perl, but can someone explain the following code example from here (slightly simplified)? sub test{ my %hash; @hash{@_} = (undef) x @_; } Example Call to sub: test('one', 'two', 'three'); This line is what throws me: @hash{@_} = (undef) x @_; It is creating a ha...

How to parse multi record XML file ues XML::Simple in Perl

Hello. My data.xml <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="UK"> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <price>10.0</price> </cd> <cd country="CHN"> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <price>9.99</price> </cd> <cd country="USA"> ...

Garbage collection in Perl

Unlike Java, Perl uses reference count for garbage collection. I have tried searching some previous questions which speak about C++ RAII and smart pointers and Java GC but have not understood how Perl deals with the circular referencing problem. Can anyone explain how Perl's garbage collector deals with circular references? Is there an...

Global Variable, subroutine variable Question in Perl

Hello. How can I transfer the subroutine variable value into another subroutine variable, Can I use global variable. sub foo(){ my $myvar = "Hello"; } sub foo1(){ my $myvar1 = $myvar; # how can I get the "Hello" from $myvar. } I tried to use package and global variable, but failed. Package Bar; our $bar; Thank you. ...

dereferencing hash without creating a local copy

Hi, I the code bellow line 9 creates a local copy of a hash. Any changes to the %d will not provide changes to global %h variable (line: 5). I have to use reference (line: 8) to provide changes to %h. Is there any way to dereference hash in a sub without creating a local copy? I am asking since I have complicated record with many refer...

how to add record in alphabetical order

A File contains (a.txt) # this is test file Data: 15th may 2010 Records : a b c d g l just consider if i want to add new record "f" - i want addit in betwen d and g ...

Perl Class::Accessor failure, trivial example - why ?

Can someone tell me why the main does not find the methods generated by Class::Accessor in this very small and trivial example ? These few lines of code fail with perl codesnippets/accessor.pl Can't locate object method "color" via package "Critter" at codesnippets/accessor.pl line 6. see the code: #!/opt/local/bin/perl # The whole...

PCRE (recursive) pattern that matches a string containing a correctly parenthesized substring. Why does this one fail?

Well, there are other ways (hmmm... or rather working ways) to do it, but the question is why does this one fail? / \A # start of the string ( # group 1 (?: # group 2 [^()]* # something other than parentheses (greedy) | # or \( (?1) \) # parenthesized group 1 ) ...

semantics in perl

i am new to perl and was asked to do a documentation on the semantics of perl.i did find some information but i cannot understand them.can some one explain it to me ion a simple way?a very simple explanation is enough.no need to go to deapth. explain how axiomatic,operatioonal and denotational semantics are implemented in perl thank you ...

Is there any way to allow failed uploads to resume with a Perl CGI script?

The application is simple, an HTML form that posts to a Perl script. The problem is we sometimes have our customers upload very large files (gt 500mb) and their internet connections can be unreliable at times. Is there any way to resume a failed transfer like in WinSCP or is this something that can't be done without support for it in th...

How can I keep memory from exploding when child processes touch variable metadata?

Linux uses COW to keep memory usage low after a fork, but the way Perl 5 variables work in perl seems to defeat this optimization. For instance, for the variable: my $s = "1"; perl is really storing: SV = PV(0x100801068) at 0x1008272e8 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x100201d50 "1"\0 CUR = 1 LEN = 16 When you use tha...

How can I do a CVS checkout without using the Cvs module?

How to do CVS co using Perl without using Cvs module ? ...

Perl How to get the index of last element of array reference?

If we have array then we can do following: my @arr = qw(Field3 Field1 Field2 Field5 Field4); my $last_arr_index=$#arr; How do we do this for array reference? my $arr_ref = [qw(Field3 Field1 Field2 Field5 Field4)]; my $last_aref_index; # how do we do something similar to $#arr; ...

How do I dynamically discover packages from a partial namespace in perl?

I have a directory structure that looks like: Foo::Bar::Baz::1 Foo::Bar::Baz::2 etc Can I list the packages from something like: use Foo::Bar::Baz; Thanks! Edit: Made it more clear what the modules are. ...