Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

The Monastery Gates

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

Donations gladly accepted

  • (Sep 10, 2018 at 22:53 UTC) Welcome new users!
If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Spreadsheet::Read Win32::LongPath::openL
2 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 09, 2018 at 08:48

    Hi

    I am trying to open Excel and ODS files with longnames paths (and possibly not Latin characters) on Windows. I use Win32::LongPath::openL to open the files. For XLS I then use Spreadsheet::ParseExcel. This works fine. For ODS I use Spreadsheet::Read. This doesn't work.

    use Spreadsheet::Read; use Spreadsheet::ParseExcel; my $InputFile; Win32::LongPath::openL (\$InputFileReadable, '<', $InputFile); #opening XLS my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($InputFileReadable); if ( defined $workbook ) { print "I could read the XLS file\n"; } #opening ODS my $workbook2 = ReadData ($InputFileReadable); if ( defined $workbook2 ) { print "I could read the ODS file\n"; }

    Why is $workbook2 always undefined?

Browser::Open Windows metacharacters
2 direct replies — Read more / Contribute
by IB2017
on Dec 09, 2018 at 05:08

    Hello Monks,

    is it a bug in Browser::Open or a 'bug' in my module understanding? The following doesn't work on Windows 10:

    my $url='https://www.google.com/search?q=finance&source=lnms&tbm=isch' +; my $ok = open_browser($url);

    It breaks after shell metacharacters (in this case &) which Windows is trying to use as commands. Should I pass $url in a different way?

code duplicate in tests -- code or custom module only needed to test
4 direct replies — Read more / Contribute
by Discipulus
on Dec 06, 2018 at 05:42
    Hello folks!

    I'm writing a lot of test nowadays (finally!) and currently I have a lot of duplicated code in them. This is because I'm testing a simple backup solution and many tests of mines requires backup scenarios to be present in a temporary folder.

    So I create and delete files and folders in my tests, I read a write files permissions etc.. and to accomplish these tasks I use CPAN modules not needed by my module but only during tests.

    1) I can have a dedicated module with all required modules imported an exposing all subs I need. Where? How? Where the dependencies of this (somehow private module) have to be specified? In the BUILD_REQUIRES in the Makefile.PL of the main module?

    2) have a special part of the main module (or a dedicated package?) loaded only during tests? How to trigger this behaviour?

    3) (probably worst approach) build only one test file, a big one with all modules used and all subs defined in the very same file

    I did not found anything related to the matter (maybe because of generic terms of the search..) nor advice in my bibliotheca and asking in the chatter box I had a precious suggestion by Corion that i'll present below (for future readers) but I also want to know from you other possible approaches or tecniques, and if i missed some detail:

    Corion suggested option 1: and pointed me to his WWW-Mechanize-Chrome's helper.pm testing module. The solution is simple and worth to share (I see # hide from CPAN indexer can some elaborate this?).

    Have you other approach? Some quirk I missed? Something to pay attention to?

    thanks



    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Multiuser app with SQLite, Dancer2 and CLI
5 direct replies — Read more / Contribute
by kaldor
on Dec 04, 2018 at 16:02

    Hello, this is my first question...

    I'd like to write a small multi-user text application accessible by different interfaces (web, terminal, ssh and maybe others). The typical scenario is a few hundreds total users, with a dozen users connected at the same time.

    I have the following prototype working : SQLite + DBI + Dancer2 web app running as FastCGI (on mac/linux). Now I wonder how to add CLI interfaces without duplicating code and logic... As fas as I understand, the SQLite "file" can be accessed safely by different processes.

    Should I just write a basic CLI that accesses the DB directly and use xinetd? Or do I have to write a backend that accesses the DB and executes the logic for UI-only clients?

    Suggestions and advice are welcome. Thank you.

Turning regex capture group variables into arrays, then counting the number of objects in the array
4 direct replies — Read more / Contribute
by Djay
on Dec 04, 2018 at 06:51

    Hi Monks,

    I've been working on building a small script, equivalent to a Powershell Script I've already written (but this time for Linux), which essentially takes the output of a command, regex's it, chucks all the capture groups into separate arrays and counts the number of objects in each array. This is reasonably complicated (for me) in Powershell, but can be accomplished through clever use of hashtables.

    I am a complete and utter Perl novice, with literally no experience in the language. I've tried to do the above with Bash but it seems so limited, and my Regex is using PCRE. I've tried using the Perl one liner but I cant seem to call the capture group variables into an array in bash to count them.

    Below is a sample output from the command

    JobID Type State Status Policy Schedule + Client Dest Media Svr Active PID 41735 Backup Done 0 Policy_name_here daily + hostname001 MediaSvr1 8100 41734 Backup Done 0 Policy_name_here daily + hostname002 MediaSvr1 7803 41733 Backup Done 0 Policy_name_here daily + hostname004 MediaSvr1 7785 41732 Backup Done 0 Policy_name_here daily + hostname005 MediaSvr1 27697 41731 Backup Done 0 Folicy_name_here daily + hostname006 MediaSvr1 27523 41730 Backup Done 0 Policy_name_here daily + hostname007 MediaSvr1 27834 41729 Backup Done 0 Policy_name_here - + hostname008 MediaSvr1 27681 41728 Backup Done 0 Policy_name_here - + hostname009 MediaSvr1 27496 41727 Catalog Backup Done 0 catalog full + hostname010 MediaSvr1 27347 41712 Catalog Backup Done 0 catalog - + hostname004 30564

    I'm terrible with HTML so I don't know how to fix the text wrapping in the above output

    Below is my regex (which works in Powershell)

    /(\d+)?\s+((\b[^\d\W]+\b)|(\b[^\d\W]+\b\s+\b[^\d\W]+\b))?\s+((Done)|(A +ctive)|(\w+\w+\-\w\-+))?\s+(\d+)?\s+((\w+)|(\w+\_\w+)|(\w+\_\w+\_\w+) +)?\s+((b[^\d\W]+\b\-\b[^\d\W]+\b)|(\-)|(\b[^\d\W]+\b))?\s+((\w+\.\w+\ +.\w+)|(\w+))?\s+((\w+\.\w+\.\w+)|(\w+))?\s+(\d+)?/g

    In the Script I have for windows, each capture group corresponds to the columns on this table, and my script counts the objects within each capture group (thus counting the number of failed, successful, running backups etc.

    I have no code written in Perl other than the following (which doesn't work for my purpose and was Frankenstein'd from much googling)

    #!/usr/bin/perl # use strict; use warnings; my $output = `bpdbjobs`; while (my $line = $output) { chomp $line; my @array = $line =~ /(\d+)?\s+((\b[^\d\W]+\b)|(\b[^\d\W]+\b\s ++\b[^\d\W]+\b))?\s+((Done)|(Active)|(\w+\w+\-\w\-+))?\s+(\d+)?\s+((\w ++)|(\w+\_\w+)|(\w+\_\w+\_\w+))?\s+((b[^\d\W]+\b\-\b[^\d\W]+\b)|(\-)|( +\b[^\d\W]+\b))?\s+((\w+\.\w+\.\w+)|(\w+))?\s+((\w+\.\w+\.\w+)|(\w+))? +\s+(\d+)?/g; foreach my $s (@array) { print "'$s'\n"; } }

    Any help would be greatly appreciated - cheers

german Alphabet
3 direct replies — Read more / Contribute
by shreedara75
on Dec 04, 2018 at 00:31
    I am trying insert a German Text with German Alphabet in an Excel Cell. however what i have stored in a variable and what is printed in XL Cell are different. i assume it is something to do with character encoding. i tried few things but could not figure out a way to insert proper German string in XL. below is my code.
    #!/usr/bin/perl use warnings; #use strict; use Encode qw(encode decode); my $enc = 'utf-8'; my $germanText = 'Fräsen und ndk (Kamera - Fräsaufnahme)'; my $germ_str = decode($enc, $germanText); my $g8txt = encode($enc, $germanText); print encode($enc, $germanText); print encode($enc, $germ_str); $xl_form = "C:/tmp/german.xls"; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{DisplayAlerts} = 1; $Book = $Excel->Workbooks->Open($xl_form); $Sheet = $Book->Worksheets("DRC"); $Sheet->Range("B2")->{Value} = $germanText; $Sheet->Range("B3")->{Value} = $germ_str; $Sheet->Range("B4")->{Value} = $g8txt;
    but in XL B2-B4 cells has the following string

    B2 = Fräsen und ndk (Kamera - Fräsaufnahme)

    B3 = Fräsen und ndk (Kamera - Fräsaufnahme)

    B4 = Fräsen und ndk (Kamera - Fräsaufnahme)

    how do i insert German text properly in XL?
Taking argument via drag-drop to a perl script
1 direct reply — Read more / Contribute
by exilepanda
on Dec 03, 2018 at 23:11
    Hello monks, I am working on Windows, and have associated .plx as direct run perl script. It means, when I double click on a .plx file, Windows will invoke the perl interpreter to run the script file. Now I wonder if I can drag drop another dir/file/shortcut to the .plx file, and the .plx file could somehow retrieve the file path as argument.

    I actually have a workable solution, which is to create a .bat file as the argument taking interface, and then forward to the script via %1 %2... But I'd like to see if this can be more straight forward (ie. directly drop on the .plx file). Thank you very much for any clues.

Recursive Class:Struct syntax error?
6 direct replies — Read more / Contribute
by ibm1620
on Dec 03, 2018 at 10:13
    Hi --

    I could use a little help learning Class:Struct. I want to traverse a directory, visiting only certain subdirectories to find files that need to be documented. The directories I want to visit are:

    bin js js/WATS php php/web_crawler
    (There will be other sub-subdirectories added later)

    Referring to perldoc for Class:Struct, I tried to create such a tree at compile time:

    use Class::Struct DOCUMENTABLE_PATHS => { bin => { }, js => { WATS => { } }, php => { }, scripts => { web_crawler => { } }, };
    The compile-time error I receive points to the use line:
    'HASH(0x24a2fd8)' is not a valid struct element type
    I'm guessing it doesn't like the way I'm recursing, but I'm stuck.

    Maybe this isn't the best way to solve this problem, but I would like to add Class:Struct to my toolbelt. Thanks for any help.

    Chap

New Meditations
Camel vs. Gopher
3 direct replies — Read more / Contribute
by reisinge
on Dec 08, 2018 at 14:16

    I've been using Perl for several years mostly for small to medium sized programs of sysadmim type (automation, gluing, data transformation, log searching). Recently I started to learn Go. I wanted to write something in both languages and compare. Here goes.

    The Perl code is more than 2 times smaller:

    $ ls -l x.* | perl -lanE 'say "$F[8]\t$F[4] bytes"' x.go 694 bytes x.pl 294 bytes

    Perl code is more than 4 times slower when run ...

    $ time go run x.go > /dev/null real 0m1.222s user 0m1.097s sys 0m0.220s $ time perl x.pl > /dev/null real 0m5.358s user 0m4.778s sys 0m0.497s

    ... and more than 5 times slower when I built the Go code:

    $ go build x.go $ time ./x > /dev/null real 0m0.947s user 0m0.890s sys 0m0.126s

    The code generates 10 million random integers from 0 to 9. Than it counts the occurrence of each generated integer and prints it.

    $ cat x.go package main import ( "fmt" "math/rand" "time" ) func main() { // Seed the random number generator seed := rand.NewSource(time.Now().UnixNano()) r1 := rand.New(seed) // Generate random integers var ints []int for i := 0; i < 10000000; i++ { n := r1.Intn(10) ints = append(ints, n) } // Count ints occurrence count := make(map[int]int) for _, n := range ints { count[n]++ } // Sort ints var intsSorted []int for n := range count { intsSorted = append(intsSorted, n) } // Print out ints occurrence for n := range intsSorted { fmt.Printf("%d\t%d\n", n, count[n]) } } $ cat x.pl #!/usr/bin/perl use warnings; use strict; # Generate random integers my @ints; push @ints, int rand 10 for 1 .. 10_000_000; # Count ints occurrence my %count; $count{$_}++ for @ints; # Print out ints occurrence for my $int ( sort keys %count ) { printf "%d\t%d\n", $int, $count{$int}; }

    In conclusion I must say that I like both languages. I like beer too :-).

    Always rewrite your code from scratch, prefefably twice. -- Tom Christiansen
Delegating responsibility of one's CPAN distributions
4 direct replies — Read more / Contribute
by stevieb
on Dec 04, 2018 at 20:21

    Say, for example, I get eaten by a bear, roll my truck off into the lake, get crushed by falling mountain boulders or otherwise burn in a fire, I'm wondering what will happen with my CPAN distributions.

    I mean, I won't care if I'm dead, but if they are being used (from what I can tell, they are in a 'minimalistic' sense (I don't know numbers)), what happens? By default after years of trying to understand, they'll fall into a state of disrepair and then go through the normal channel of adaption.

    I'm wondering what my fellow Monks think about this.

    My question here, is would it be worth working it up the chain to have a "will" of sorts; someone you could "dedicate" your distributions to, within the Makefile (or whatever dist thingy one uses). A new attribute, effective across all build platforms and accepted by CPAN, that acknowledges who you want to oversee what you've written.

    I'm not talking about co-auth here. I'm talking about someone who may not even care about one's work. I'm talking about someone who cares about Perl enough that one would feel comfortable with rightfully distributing one's distributions accordingly, because they are somewhat familiar with the Perl ecosystem.

    This is totally off the wall, but I've been through so much in the last 24 months, that I'm trying to think of everything.

    Would a IF_I_DIE flag within a Makefile.PL that is easily searchable be a good idea, or an idea of a madman who keeps buying sensors to write Perl around?

New Obfuscated Code
Christmas Package Obfuscation
1 direct reply — Read more / Contribute
by kschwab
on Dec 08, 2018 at 14:11
    #!/usr/bin/perl $;;$^;s#^#$\ _-~,..___ .-' .--._ ```--.-----.___ ._^---- (`-...`-. _/,----. ) ````---=. _.-'' ````-- `.___.-.) (---=='' .-' | _.-' _.-. )(`.-._``--.._ .' | |`---..__ .-'.-'.' )| |_ ``--...`. | | ``--.._ ,'.-' ( ( `-.`-. .'| : | | | | --.._`. ) `. `. | : | | | | ( )-.._.') ) ) : | | | | | | | ( ( ) : | | | | (_( | ) ) | : .' | | | | L/ | : .' (__ | | | | :.' `-.._ | | | | : `-.._ | | | |/ `--`_|_ | .' `._ | .' ``-.__ | .' `--`; # and "Happy Holidays" or Merry Christmas! print "Is print broken?\n";print;# guess not?
perl: we package API -- oneliner
1 direct reply — Read more / Contribute
by Discipulus
on Dec 07, 2018 at 07:11
    perl -we "package API{$|++;$'__=__PACKAGE__;$\"=','}print/J$__/?exit:q +q($_\r)for glob qq{{@{[A..P,I]}}}x4"

    Note: Win32 double quotes!

    Thanks Tux, thanks Eily

    L*

    PS changed the title from empty API package -- oneliner to the current

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-12-10 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many stories does it take before you've heard them all?







    Results (47 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!