Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Activestate Perl 5.20, Change make/compiler
1 direct reply — Read more / Contribute
on Oct 06, 2015 at 09:32
    I have installed Activestate Perl 5.20 on a Windows 2012 Server. The default settings for make/Compiler are 'dmake' and 'mingw'. So i installed Visual Studio Express and the MS SDK. I put the dirs in the PATH, executed 'vcvars*', but when trying to install a certain module, i always get the error that the MS Compiler is needed but only 'mingw' is available. I need to install Win32::GUI::Grid and it only Compiles with MSVC... I can install Win32::GUI without any error show, but in fact win32::GUI::Grid and at least win32::GUI::axWindow are mnot installed. I also cannot switch to linux or another Perl Distribution, since I have to 'compile' with PerlApp. An suggestions where or how to change the settings?
Text filer and assign
2 direct replies — Read more / Contribute
by intoperl
on Oct 06, 2015 at 04:13

    Hello Monks, I want to filer some text from a linux output, and store it in variable for report purposes. Below is the text i am processing

    PV /dev/sda2 VG VGExaDb lvm2 [557.62 GB / 20.50 GB free] PV /dev/sda3 VG VGExaDb lvm2 [278.88 GB / 0 free]

    So, from above text, i want to extract (/dev/sda2) (/dev/sda3) and 557.62 GB / 20.50 GB free. I did write a regex code which is not working for me. Please assist. Thanks

What does '::' mean in constructs '$::foo' and '@::foo'?
3 direct replies — Read more / Contribute
by jmeek
on Oct 06, 2015 at 02:50

    In Damian Conway's "Abbot and Costello Who's on First'" Parse::RecDescent example code in "Computer Science & Perl Programming" he starts the code with the line

    use vars qw( %base %man @try_again);

    and then in the action blocks in the grammars uses those variables with the syntax, e.g., $::man{$item[4]} and @::try_again.

    As I thought the point of the 'use vars' pragma was to allow the variables to be used globally without writing the fully qualified name, I'm puzzled as to why the double colons are used.

Perl OPC
2 direct replies — Read more / Contribute
by TFarmer
on Oct 05, 2015 at 14:58
    Im looking for code to use WIN32::OLE::OPC to read and write to a single tag on a channel/device I just need to read and write the value of the tag
call external sub ref from method in single line
4 direct replies — Read more / Contribute
by previous
on Oct 05, 2015 at 09:09
    Can I call a reference to an external sub (supplied via the constructor) from inside an object method using a single line instead of the two I've used.
    sub new { my $class = shift; my $self = {}; bless( $self, $class ); $self->{num} = shift; $self->{sub_ref} = shift; # JUST PASSING IN....REFERENCE TO EXTERN +AL SUB...\&ord_sub return $self; } sub doit { my $self = shift; #QUESTION...CAN I REDUCE THE NEXT TWO LINES TO ONE my $pSub=$self->{sub_ref}; $pSub->(); }
    Thank you in anticipation
Best practices for warnings about wrong context
5 direct replies — Read more / Contribute
by vsespb
on Oct 04, 2015 at 11:38

    Let's suppose I've created a library with the following API:

    sub myfunc { my ($ref) = @_; # modify $ref somehow warn "Should be called in void context" if defined wantarray; }

    The function does something, but does not returns anything useful. It returns nothing. I can add "return ;" but this does not change things - function returns nothing and I don't want it to be used in non-void context. Purpose of the last warning in function is simple: the function returns nothing, and if someone called it in scalar/list context, he's doing something wrong. So this warning adds more strictness to user's code:

    examples of user's code:

    example 1:

    func1(); myfunc($data); func2();

    everything ok - no warning

    example 2:


    there will be the warning! user obvious did something wrong here!

    example 3:

    sub anotherfunc { # .. code here myfunc($data) } func1(anotherfunc())

    there will be the warning! and indeed this code isn't sane.

    So far everything going well, and the warning seems useful.

    However, let's look on Catalyst now:

    sub xxx : Local Args(0) { my ($self, $c, $s, $r, $p) = @_; $c->res->body( wantarray ); }

    It's the Catalyst action, which return value is ignored, but it's called in list context.

    Sometimes action return value is important (see "Any data returned from the action forwarded to, will be returned by the call to forward." in manual), sometimes no. But catalyst always call actions in list context.

    Now the quesions:
    (a) Is that good practice to create library, which warns for "defined wantarray" for functions, returning nothing?
    (b) Are libraries like catalyst obligated to never call user's callback in non-void context if it's value is ignored?
    I assume if (b)=no, then (a)=no.
    Is there a convention for such kind of things? (or let me rephrase: if I am getting this warning when using my library with Catalyst, who's fault is that? the library's or Catalyst's)

removing leading 0's
4 direct replies — Read more / Contribute
by CSharma
on Oct 03, 2015 at 11:48
    Hi PMs, The output should be "10 & 10 are equal", but this gives output "10 & 8 aren't equal". I don't understand this! perhaps because of leading 0's perl converted 0010 to octel i.e. 8
    I tried removing leading 0's, still the same output "10 & 8 aren't equal".

    Please help to overcome this.
    Actually I'm reading values from a file in which lots of values have leading 0's & I have to compare this value to some other from different file which doesn't have leading 0's.
    #!/usr/bin/perl $x = 10; $y = 0010; $y =~ s/^0+//; ##OR $y += 0; if($x == $y) { print $x . " and " . $y . " are equal\n"; } else { print $x . " and " . $y . " aren't equal\n"; }
Handling japanese file & comparison
2 direct replies — Read more / Contribute
by CSharma
on Oct 02, 2015 at 14:16
    Hi PerlMonks,

    1. A Japanese compressed file(tab separated), Say A having products information (iphone etc), columns: name, description, image, uniqueid, rid1, rid2, url
    2. Another file, say B having mid, rid, ntid (column separated).
    3. rid1, rid2 => A & rid => B are numerical values.

    What I want:
    If rid from B matches rid1(from A), get that line form A into third file, Say C. In case, rid is null then rid(from B) to be matched with rid2 (from A). If rid1 & rid2 don't have values, leave that line.
    Also I've to add some values to the url (from A) & then it's to be pushed to 3rd file C after rid comparison.

    The main problem I've are:
    1. How to handle the japanese? Do I have to use any modules? as saving the japanese character to a perl variable turn to junk.
    2. There are 30 files like file A, each having 1 million of lines in them. What would be the efficient way to do this in perl?

    Help is much appreciated!

XML::SAX parameters
1 direct reply — Read more / Contribute
by Artimus
on Oct 02, 2015 at 08:53

    Hi everyone!

    I wonder if someone could explain me the way I can pass parameters to my SAX handler or, maybe receive smth back after $parser->parse_file($fh) worked.

Perl Modules Scope ?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 02, 2015 at 02:01
    Hi, I am writing a login screen and and have following files:
    lib.cgi and login.cgi
    in i have following code:
    package config; our $abcd = 1; 1;
    in lib.cgi i have following code:
    use config; 1;
    in login.cgi i have following code:
    use strict; required 'lib.cgi'; print $config::abcd;
    on compiling this I get an error. The error goes away if i "use config" in login.cgi. I thought since I am including lib.cgi inside login.cgi I would not have to use config inside login.cgi Please help me understand this better
Use LWP get no URL response
3 direct replies — Read more / Contribute
by hoanglearning
on Oct 01, 2015 at 20:32

    My program don't get URL response in search for capacitor part from DIGI-key. I received good response when URL is typed in directly on Google Chrome browser. When running my program, it shows the HTTP status of 302 without URL redirect and no response is received. Please help to point out what wrong with my codes. Thanks so much in advance

    use strict; use warnings; use LWP; my $browser = LWP::UserAgent->new; $browser->env_proxy; my $url = ' +74K4PACTU&WT.z_header=search_go'; my $response = $browser->get( $url ); print "HTTP status: ", $response->code( ), "\n"; unless ($response->is_success) { print "no response\n"; } my $response_content = $response->content; print "response_content= $response_content\n";

    The modified codes from Sathishkumar resolved this problem. Sathishkumar, thanks verymuch. I got your codes and it's working. I still need to learn the line "$cookie->extract_cookies($res);" to see what it exactly doing. I also like to thanks Perlmonk and MidLifeXis. I can't not get this problem solved without your help.

Handling SIG INT multiple times
1 direct reply — Read more / Contribute
by delight
on Oct 01, 2015 at 10:15
    Hello guys I'm using sig int to communicate between my class and the script who use it. In detail i'm using signals to change the flow of the script in certain situation. This works okay but the problem is that my sig int handler looks something like:
    sub handler { # call some log stuff here a_function() if($myobject->{something} eq 'lorem'); b_function() if($myobject->{something} eq 'ipsum); #etc }
    my class send a signal to change the flow of the script in some scenarios, so its just a: kill 'INT', $$; Thing is that after the first okay the handler runs a_function() ( which is a long running function who dont return) if something happens and the class sends another kill, handler() will not be called because, I guess, for the OS or Perl we are still handling the first signal. So my question is there's a solution?
New Cool Uses for Perl
Edit files automatically cross-platform, line-endings unknown
No replies — Read more | Post response
by stevieb
on Sep 30, 2015 at 16:56

    I had a need for a piece of my software to be platform independent when reading/writing files with any type of line endings. So, I'm sure there are better/more efficient ways to do this, but I couldn't find one and really wanted to better understand record separators, so I wrote File::Edit::Portable.

    This module will read in a file on any platform, save the existing record separators (line endings), and modify them to the local platforms endings for use. It'll return either a file handle or an array of the file contents.

    You can optionally then push back an array of contents, and the module will rewrite the file (or optionally a new one), using the line endings that were found while reading (or optionally a user supplied one). This means it'll open Unix files on Windows and rewrite the file with Unix endings, and vice-versa on Windows and Mac (the three I've tested).

    use warnings; use strict; use File::Edit::Portable; my $rw = File::Edit::Portable->new; my $recsep; $recsep = $rw->recsep('unix.txt'); print "unix file before write: $recsep\n"; $recsep = $rw->recsep('win.txt'); print "win file before write: $recsep\n"; my $ufh = $rw->read(file => 'unix.txt'); my @unix_contents = <$ufh>; close $ufh; $rw->write(contents => \@unix_contents); $recsep = $rw->recsep('unix.txt'); print "unix file after rewrite: $recsep\n"; my $wfh = $rw->read(file => 'win.txt'); my @win_contents = <$wfh>; close $wfh; $rw->write(contents => \@win_contents); $recsep = $rw->recsep('win.txt'); print "win file after rewrite: $recsep\n";


    # unix $ ./ unix file before write: \0a win file before write: \0d\0a unix file after rewrite: \0a win file after rewrite: \0d\0a # windows E:\test>perl unix file before write: \0a win file before write: \0d\0a unix file after rewrite: \0a win file after rewrite: \0d\0a

    We've also got a non-OO interface:

    use File::Edit::Portable qw(pread pwrite); my $fh = pread('file.txt'); # or even my @contents = pread('file.txt'); # then, later pwrite('file.txt', \@contents);

    I definitely know it's quite inefficient, but it's my first working prototype. There are a lot of things missing (unicode and open filters for instance). Criticisms or existing ways to do this are very welcome.


New Monk Discussion
How can one find his previous preview page (uncreated)?
2 direct replies — Read more / Contribute
by u65
on Oct 03, 2015 at 11:48

    Is there a procedure for finding an uncreated preview node?

    A couple of times now I've started a post but got interrupted before I pushed "create" and so far have found no reliable way to easily find what I started. If I don't go too far astray, I can keep pushing the back arrow in my browser and find it, but if I log off or otherwise close the page I can't always find it again. I have not been able to find much searching about preview here except the threads on wanting a preview capability for updates.

    Note that when working on longer posts I've kept text in an offline file to edit and copy from, but that seems to be a pain for relatively small posts, but I guess I could make that a habit.


Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2015-10-06 17:26 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (155 votes), past polls