Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
mod_perl best practices to increment XML payload
No replies — Read more | Post response
by glasswalk3r
on Jun 22, 2017 at 17:23

    Hello monks,

    I've being studying mod_perl in the past to implement a project that uses Apache as a reverse proxy, receives a SOAP request, modifies the payload (XML), handles it to the real web application, and returns back the response to the requester.

    What is the best practice in this case? I checked out Apache::ReverseProxy, but it defines a full handler and I'm guessing that using a Input or Output filter handler would be a better option (based on my readings of mod_perl2 User Guide book) combined with the standard Apache modules proxy and proxy_http to avoid reinventing the wheel.

    PS: I know mod_perl2 is not the "sexiest" framework at the moment, but I want to take advantage of already having it available on particular web servers by default.


    Alceu Rodrigues de Freitas Junior
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Pulling from a list and inserting into XML documents
3 direct replies — Read more / Contribute
by gng4life
on Jun 22, 2017 at 09:25
    Hello All, First post so go easy on me. I'm getting back into Perl after not touching it for years so I am like a noob. This is what I need to do. I have text file A that three fields, for example IP address, MAC, hostname, and there about 200 of them, comma separated (I can change this to a csv or whatever if easier). I have about 200 XML documents that I need to search for tags and enter those three fields above into that section, save it, open the next document and enter the same three fields, save, repeat for all docs. Here is an example:
    File A hosta,,00000C123456, hostb,,00000C123457, hostc,,00000C123458, hostd,,00000C123459, etc...(about 200 items, will have more later) File 1 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 2 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 3 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . After all the docs are done, they will look like this... File 1 . <HOST_NAME>hosta</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123456</HOST_MAC> . . File 2 . <HOST_NAME>hostb</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123457</HOST_MAC> . . etc.
    I have portable strawberry Perl right now on my work computer. If it would be easier to do it in ActivePerl or in Strawberry Perl installed version, let me know and I can spin it up on another workstation. So what is the best way to do this? Thanks for any help!
from txt file to array
6 direct replies — Read more / Contribute
by WisDomSeeKer34
on Jun 21, 2017 at 15:01

    I have raw data like this:

    New York

    and I want to turn it into an array:
    qw (Washington, New York ....);

    I can do it manually but it is a fuzz to do it every time.
    Is it perhaps possible with while (< DATA >)? How to input raw data into a perl script?

using a 'here' doc to build a web page
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 21, 2017 at 11:23
    I am constructing a web page by first defining variables which are extrapolated in the 'HERE' document. I am creating a HTML file by printing the 'HERE' document. It seems to be working OK. Is this a valid approach?
How to tie a lexical filehandle.
1 direct reply — Read more / Contribute
by clueless newbie
on Jun 20, 2017 at 15:28


    I can do a tie on a file as long as I use bareword filehandles. ie

    package MyTie; use Carp; # So we can croak our error use Data::Dumper; use strict; use warnings; sub TIEHANDLE { #Carp::cluck "\nTIEHANDLE: ",Data::Dumper->Dump([\@_], +[qw(*_)]),' '; no warnings; my $class=shift; my $form=shift; open (my $self,$form,@_) # or Carp::cluck "can't open $form@_: $!" ; return bless $self,$class; # $self is a glob ref } sub CLOSE { #Carp::cluck "\nCLOSE: ",Data::Dumper->Dump([\@_],[qw(*_)] +),' '; my $self=shift; return close $self; } sub DESTROY { #Carp::cluck "\nDESTROY: ",Data::Dumper->Dump([\@_],[qw( +*_)]),' '; my $self=shift; $self->CLOSE; } sub EOF { #Carp::cluck "\nEOF: ",Data::Dumper->Dump([\@_],[qw(*_)]),' +'; my $self = shift; return eof $self; } sub FILENO { #Carp::cluck "\nFILENO: ",Data::Dumper->Dump([\@_],[qw(*_ +)]),' '; my $self=shift; return fileno $self; } sub OPEN { #Carp::cluck "\nOPEN: ",Data::Dumper->Dump([\@_],[qw(*_)]), +' '; my $self=shift; my $form=shift; $self->CLOSE; open($self,$form,@_) or croak "can't reopen '$form@_': $!"; return 1; } sub READLINE { #Carp::cluck "\nREADLINE: ",Data::Dumper->Dump([\@_],[q +w(*_)]),' '; my $self=shift; return undef if $self->EOF; #warn Data::Dumper->Dump([\(my $t=wantarray())],[qw(*wantarray)]), +' '; if (wantarray()) { my @a=<$self>; main::mySub(@a); return @a; } else { my $s=<$self>; main::mySub($s); return $s; }; } package main; use strict; use warnings; my $name='mydata'; tie *FOO,"MyTie"; open(FOO,'<',$name) or die "Can't open '$name' for reading. $!"; my $line=<FOO>; print "Scalar: $line"; $line=<FOO>; print "Scalar: $line"; my @array=<FOO>; print "Array: ",@array; while (<FOO>) { print "In while: $_"; } close(FOO); exit; sub mySub { warn "\nmain::mySub: ",Data::Dumper->Dump([\@_],[qw(*_)]),' '; return; }; __DATA__

    works just fine to record what is read from *FOO.

    But I need to tie a lexical filehandle so I can write

    package main; use strict; use warnings; my $name='mydata'; my $FOO; tie $FOO,"MyTie"; open($FOO,'<',$name) or die "Can't open '$name' for reading. $!"; my $line=<$FOO>; print "Scalar: $line"; $line=<$FOO>; print "Scalar: $line"; my @array=<$FOO>; print "Array: ",@array; while (<$FOO>) { print "In while: $_"; } close($FOO); exit;

    But this throws 'Can't locate object method "TIESCALAR" via package "MyTie" at ...' - where the tie is attempted. Any ideas on how to tie a lexical filehandle?

    "This is perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x86-multi-thread-64int"

error variables after IPC::Run
4 direct replies — Read more / Contribute
by CarolinaPerler
on Jun 19, 2017 at 11:47

    Using IPC::Run.
    Would like to examine all the built-in special error variables: $@, $!, $^E, and $?. After an IPC::Run 'run', when I try to check $! and $^E, I get 'Illegal seek'.

    run (\@commandArray, \$in, \$error, timeout(3)); print "LIB LEVEL ERROR: $!\n"; print "OS LEVEL ERROR: $^E\n";

    On some systems in some situations, $^E is not supported. But, $! should be available. IPC::Run hands back $error (given the code above). But, it does not necessarily give back all the detail that can be gleaned from cruising through the built-in error vars. I like using IPC::Run and would like to continue doing so. But, need a robust mechanism for catching error info. It appears that IPC::Run is monkeying with $! and $^E. Any ideas on how to capture the error detail after an IPC::Run run call?

How to ask user for file name and save the output to a new text file
2 direct replies — Read more / Contribute
by mmazlan67
on Jun 18, 2017 at 23:36

    Hi, i am really new to Perl because before this i worked on Excel VBA. For now i have 3 different perl scripts in VNC that i plan to combine them into one.

    The first script will ask user for file name (e.g summary.txt), find the matching string in the summary.txt and saved the output in inout.txt using command on console "perl summary.txt > inout.txt". But error will occur Then, i run the second script just to take all the necessary data based on the requirement and saved the output in result.txt using command on console "perl inout.txt > result.txt. The third script will send result.txt to an email which can be viewed in Windows. I know that it is possible but i have no idea on how to do it as i got stuck on thinking how to open summary.txt file to read and open inout.txt to write at the same time.

    I add this code below in but then i cannot run the script on console using "perl summary.txt > inout.txt"

    print "Enter the name of the file: "; my $base_dir = <>; chomp($base_dir);open( my $DATA, "<" , $base_dir) or die "Can't open f +ile '$base_dir': $!"; while ( <$DATA> )

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while (<>) { if ($_ =~ /^\s\s(\S+)*delay\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+ +(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+) +/) { print "$_"; } }

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while ( <> ) { #if my ( $set ) = m/^\s+(\S+)/; #get the first word my ( $name,$value ) = m/-name (\S+) (\S+)/; #get the name and value my ( $mode ) = m/mode == (\S+)\"/; #get the mode print "$mode $name $set $value\n"; }

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; my $name='inoutdata'; system("uuencode /home/user/set/result.txt | mailx -s '$name' email");
System vs. User module version of List::Util
5 direct replies — Read more / Contribute
by Lady_Aleena
on Jun 17, 2017 at 21:12

    Hello. List::Util is a core module, but the system version has not been updated since 1.27. So I installed it in my user directory, and it is version 1.47. However, I am getting an error that uniq is not exported by List::Util. According to the docs, List::Util has had uniq since version 1.45. So, what do I do to get the system to look at the user installed List::Util instead of the system installed List::Util? Is there precedence in @INC? Do I have to beg the system administrators to update their List::Util?

    I went to the command line and read the perldoc for List::Util, and perldoc brought up the docs for 1.47 not 1.27. I am confused by that a bit.

    Here is my @INC from the command line, and it has my user directories first, so that makes this even more confusing.

    Here is my @INC from the browser, and it has my user directories first, so that makes this so much more confusing.

    Any and all help is appreciated.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Time::Piece reversibility
4 direct replies — Read more / Contribute
by mla12
on Jun 17, 2017 at 17:06

    I'm trying to parse a timestamp with Time::Piece, and then stringify the result back into the original date string.

    The timestamp includes the zone. I can do it with Time::Local and it works as expected. But with Time::Piece, no matter what I seem to try, the result is displayed as GMT.

    See this test:

    #!/usr/bin/env perl use strict; use warnings; use Time::Local; use Time::Piece; my $datestr = '2017-06-19 10:07:42-0700'; print "Original date string: $datestr\n\n"; print "Using Time::Local\n"; my $time = timelocal(42, 7, 10, 19, 6, 2017); print " Epoch seconds: $time\n"; print " CORE::localtime: ", scalar CORE::localtime($time), "\n"; print "\n"; print "Using Time::Piece:\n"; print " strptime as static method:\n"; my $obj = Time::Piece->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strptime as localtime instance method:\n"; $obj = localtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strptime as gmtime instance method:\n"; $obj = gmtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n";

    For me, that produces:

    Original date string: 2017-06-19 10:07:42-0700 Using Time::Local Epoch seconds: 1500484062 CORE::localtime: Wed Jul 19 10:07:42 2017 Using Time::Piece: strptime as static method: stringified: Mon Jun 19 17:07:42 2017 datetime: 2017-06-19T17:07:42 tzoffset: 0 hour: 17 strptime as localtime instance method: stringified: Mon Jun 19 17:07:42 2017 datetime: 2017-06-19T17:07:42 tzoffset: -25200 hour: 17 strptime as gmtime instance method: stringified: Mon Jun 19 17:07:42 2017 datetime: 2017-06-19T17:07:42 tzoffset: 0 hour: 17

    The CORE::localtime result is what I want. But how do I get that back out of the Time::Piece instances?

    I'm using the latest Time::Piece, 1.31

Trouble Installing Spreadsheet::Read on Dwim Perl
2 direct replies — Read more / Contribute
by cwk
on Jun 16, 2017 at 15:50

    I'm attempting to install Spreadsheet::Read from CPAN. Environment is Windows 10. Output of "perl -V" below the errors. This is what I'm seeing:

    C:\Dwimperl\src>cpan Spreadsheet::Read CPAN: CPAN::SQLite loaded ok (v0.202) Database was generated on Fri, 16 Jun 2017 19:08:14 GMT Running install for module 'Spreadsheet::Read' Running make for H/HM/HMBRAND/Spreadsheet-Read-0.72.tgz CPAN: Digest::SHA loaded ok (v5.63) CPAN: Compress::Zlib loaded ok (v2.042) Checksum for C:\Dwimperl\cpan\sources\authors\id\H\HM\HMBRAND\Spreadsh +eet-Read-0.72.tgz ok CPAN: Archive::Tar loaded ok (v1.80) CPAN: File::Temp loaded ok (v0.22) CPAN: Parse::CPAN::Meta loaded ok (v1.4401) CPAN: CPAN::Meta loaded ok (v2.120351) CPAN: Module::CoreList loaded ok (v2.57) Building H/HM/HMBRAND/Spreadsheet-Read-0.72.tgz Do you want to install 'xlscat' (Convert Spreadsheet to plain text or +CSV) ? [y] Do you want to install 'xlsgrep' (Grep pattern from Spreadsheet) ? [y +] Do you want to install 'ss2tk' (Show a Spreadsheet in Perl/Tk) ? [y] Do you want to install 'ssdiff' (Show diff between two spreadsheets) ? + [y] Do you want to install 'xls2csv' (Wrapper around xlscat for easy XLS = +> CSV) ? [y] Checking if your kit is complete... Looks good Writing Makefile for Spreadsheet::Read Writing MYMETA.yml and MYMETA.json cp blib\lib\Spreadsheet\ C:\Dwimperl\perl\bin\perl.exe -MExtUtils::Command -e cp -- examples/ss +2tk blib\script\ss2tk pl2bat.bat blib\script\ss2tk C:\Dwimperl\perl\bin\perl.exe -MExtUtils::Command -e cp -- examples/xl +s2csv blib\script\xls2csv pl2bat.bat blib\script\xls2csv C:\Dwimperl\perl\bin\perl.exe -MExtUtils::Command -e cp -- examples/xl +sgrep blib\script\xlsgrep pl2bat.bat blib\script\xlsgrep C:\Dwimperl\perl\bin\perl.exe -MExtUtils::Command -e cp -- examples/xl +scat blib\script\xlscat pl2bat.bat blib\script\xlscat C:\Dwimperl\perl\bin\perl.exe -MExtUtils::Command -e cp -- examples/ss +diff blib\script\ssdiff pl2bat.bat blib\script\ssdiff HMBRAND/Spreadsheet-Read-0.72.tgz C:\Dwimperl\c\bin\dmake.EXE -- OK CPAN: YAML loaded ok (v0.77) Running make test C:\Dwimperl\perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_har +ness(0, 'blib\lib', 'blib\arch')" t/*.t t/00_pod.t ...... ok t/01_pod.t ...... ok t/10_basics.t ... ok t/11_call.t ..... ok t/200_csv.t ..... # Parser: Text::CSV_XS-0.86 t/200_csv.t ..... ok t/201_csv.t ..... ok t/202_csv.t ..... ok t/203_csv.t ..... ok t/204_csv.t ..... ok t/205_csv.t ..... ok t/210_csv.t ..... # Parser: Text::CSV_XS-0.86 t/210_csv.t ..... ok t/211_csv.t ..... ok t/212_csv.t ..... ok t/213_csv.t ..... ok t/214_csv.t ..... ok t/220_csv.t ..... # Parser: Text::CSV_PP-1.29 t/220_csv.t ..... ok t/221_csv.t ..... ok t/222_csv.t ..... ok t/223_csv.t ..... ok t/224_csv.t ..... ok t/30_xls.t ...... # Parser: Spreadsheet::ParseExcel-0.59 t/30_xls.t ...... ok t/31_clr.t ...... ok t/32_fmt.t ...... ok t/33_misc.t ..... ok t/34_dates.t .... ok t/35_perc.t ..... ok t/36_xls.t ...... 1/177 # Failed test 'Sheet 2 is active' # at t/36_xls.t line 153. # got: '0' # expected: '1' # Looks like you failed 1 test of 177. t/36_xls.t ...... Dubious, test returned 1 (wstat 256, 0x100) Failed 1/177 subtests t/37_merged.t ... ok t/40_sxc.t ...... skipped: No SXC parser found t/45_ods.t ...... skipped: No SXC parser found t/46_clr.t ...... skipped: No OpenOffice ODS parser found t/50_sc.t ....... # Parser: Spreadsheet::Read-0.72 t/50_sc.t ....... ok t/51_sc.t ....... ok t/600_xlsx.t .... skipped: No MS-Excel parser found t/601_clr.t ..... skipped: No MS-Excel parser found t/602_fmt.t ..... skipped: No MS-Excel parser found t/603_misc.t .... skipped: No MS-Excel parser found t/604_dates.t ... skipped: No MS-Excel parser found t/605_perc.t .... skipped: No MS-Excel parser found t/607_merged.t .. skipped: No MS-Excel parser found t/610_xlsx.t .... skipped: Cannot use Spreadsheet::ParseXLSX t/611_clr.t ..... skipped: Cannot use Spreadsheet::ParseXLSX t/612_fmt.t ..... skipped: Cannot use Spreadsheet::ParseXLSX t/613_misc.t .... skipped: Cannot use Spreadsheet::ParseXLSX t/614_dates.t ... skipped: Cannot use Spreadsheet::ParseXLSX t/615_perc.t .... skipped: Cannot use Spreadsheet::ParseXLSX t/617_merged.t .. skipped: Cannot use Spreadsheet::ParseXLSX t/620_xlsx.t .... skipped: Cannot use Spreadsheet::XLSX t/621_clr.t ..... skipped: Cannot use Spreadsheet::XLSX t/622_fmt.t ..... skipped: Cannot use Spreadsheet::XLSX t/623_misc.t .... skipped: Cannot use Spreadsheet::XLSX t/624_dates.t ... skipped: Cannot use Spreadsheet::XLSX t/625_perc.t .... skipped: Cannot use Spreadsheet::XLSX t/627_merged.t .. skipped: Cannot use Spreadsheet::XLSX Test Summary Report ------------------- t/36_xls.t (Wstat: 256 Tests: 177 Failed: 1) Failed test: 175 Non-zero exit status: 1 Files=54, Tests=2615, 40 wallclock secs ( 0.84 usr + 0.69 sys = 1.53 + CPU) Result: FAIL Failed 1/54 test programs. 1/2615 subtests failed. dmake.EXE: Error code 255, while making 'test_dynamic' HMBRAND/Spreadsheet-Read-0.72.tgz C:\Dwimperl\c\bin\dmake.EXE test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports HMBRAND/Spreadsheet-Read-0.72.tgz Running make install make test had returned bad status, won't install without force
    C:\Dwimperl\src>perl -V Summary of my perl5 (revision 5 version 14 subversion 2) configuration +: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='Win32 strawberryperl #1 Tue Nov 22 21:00:59 2011 i +386' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags =' -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS -DUSE +_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-stric +t-aliasing -mms-bitfields', optimize='-s -O2', cppflags='-DWIN32' ccversion='', gccversion='4.4.7', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long lo +ng', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++', ldflags ='-s -L"C:\Dwimperl\perl\lib\CORE" -L"C:\Dwimper +l\c\lib"' libpth=C:\Dwimperl\c\lib C:\Dwimperl\c\i686-w64-mingw32\lib libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 +-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -l +mpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdl +g32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_3 +2 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=, so=dll, useshrplib=true, libperl=libperl514.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-mdll -s -L"C:\Dwimperl\perl\lib\CORE" +-L"C:\Dwimperl\c\lib"' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB +_ALLOC USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_PE +RL_ATOF USE_SITECUSTOMIZE Built under MSWin32 Compiled at Nov 22 2011 21:13:28 @INC: C:/Dwimperl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .
Find the last item in a series of files
5 direct replies — Read more / Contribute
by fredho
on Jun 16, 2017 at 10:39
    Hello Monks,
    I have several files which name has the same root and different suffix (ex: file.001, file.002, file.003) and I need to identify ,for each unique value of root value (file), the file which extension has the highest value (003)
    Do I need to push matching file into an array before sorting elements on the extension?
    Or is there an easiest way to proceed?
    Thanks for the help
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-06-22 23:26 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.