Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Tidying and simplifying a regular expression
4 direct replies — Read more / Contribute
by Dallaylaen
on Dec 08, 2017 at 12:00

    Hello monks and nuns,

    I'm just wondering if there is a module or recipe to strip a regular expression of meaningless grouping. Consider the following code:

    bash$ perl -wle 'my $rex = qr/./; $rex = qr/$rex./ for 1..10; print $r +ex;' (?^:(?^:(?^:(?^:(?^:(?^:(?^:(?^:(?^:(?^:(?^:.).).).).).).).).).).)

    It's relatively easy to spot that it's just a (?:..........), however, the expression is not stringified exactly like that. Is there a way possible to tidy it up automatically?

    Inspired by this node, but I think it would be nice to have a simplifier anyway...

seek harsh critique
3 direct replies — Read more / Contribute
by coyocanid
on Dec 08, 2017 at 11:00

    I've been working on a project for some years and want to release it to CPAN and I'm not yet happy with the POD I've written.

    I'm looking for a harsh critique of the POD below. I want to make sure it communicates the purpose and use of the module. Critique of the module is also welcome.


Looking for a cleaner regex
3 direct replies — Read more / Contribute
by k-man
on Dec 08, 2017 at 05:38

    I'm looking for a cleaner solution if one exists. I'm highlighting Spanish verb endings. The regex I came up with seems to work but I can't help but be curious if there is a better way.

    Here is what I came up with: (it's super long and I don't know how to prevent it from wrapping)

    hilite_tail () { local WORD=$1 local COLOR=$2 PFX=$(echo $WORD | perl -pe 's/(.*)(ste(?=$)|e(?<!ste)(?=$)|es(?=$ +)|is(?<!(eis|ste))(?=$)|mos(?=$)|n(?<!ron)(?=$)|o(?=$)|(?=$)|.ron(?= +$)|s(?<!(eis|.is|mos))(?=$)|steis(?=$)|(?<!u)(?=$)|(?=$)|u(?=$))/ +$1/g') SFX=$(echo $WORD | perl -pe 's/(.*)(ste(?=$)|e(?<!ste)(?=$)|es(?=$ +)|is(?<!(eis|ste))(?=$)|mos(?=$)|n(?<!ron)(?=$)|o(?=$)|(?=$)|.ron(?= +$)|s(?<!(eis|.is|mos))(?=$)|steis(?=$)|(?<!u)(?=$)|(?=$)|u(?=$))/ +$2/g') [[ $PFX != $SFX ]] && echo "${CYAN_FG}$PFX${COLOR}$SFX${RESET}" || + echo "${CYAN_FG}$WORD${RESET}" }

    Using the advice I've now simplified:

    hilite_tail () { local WORD=$1 local COLOR=$2 PFX=$(echo $WORD | perl -pe 's/(.*)(ste|(?<!st)e|es|is(?<!(eis|ste +))|mos|(?<!ro)n|o||.ron|s(?<!(.is|mos))|steis|(?<!u)||u)$/$1/g') SFX=$(echo $WORD | perl -pe 's/(.*)(ste|(?<!st)e|es|is(?<!(eis|ste +))|mos|(?<!ro)n|o||.ron|s(?<!(.is|mos))|steis|(?<!u)||u)$/$2/g') [[ $PFX != $SFX ]] && echo "${CYAN_FG}$PFX${COLOR}$SFX${RESET}" || + echo "${CYAN_FG}$WORD${RESET}" }

    Thanks

Obtaining old versions of Perl
4 direct replies — Read more / Contribute
by nysus
on Dec 07, 2017 at 22:55

    Out of curiousity, I did a quick Google search on "download 'perl 4'" and came up empty-handed. I'm figuring true comp-sci nerds would want hands on experience with earlier versions of Perl and so I have to imagine someone has got some method for running really ancient versions of Perl. Anything out there?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

-s file test operator only works in same directory
4 direct replies — Read more / Contribute
by Bowlslaw
on Dec 07, 2017 at 21:01
    Hello, I have made a perl script which takes the files from a directory listed on the command line and places them into an array of hashes with key/value pairs path:full path to file, size:size of file in bytes, and id:sha256sum of file. It works fine when I use its own directory, but it returns "undef" on the id value when used in other directories, and the $! error is "no such directory or file found", which I find quite odd considering that it lists the filenames sha256sums just fine.
    use strict; use warnings; use Data::Dumper qw(Dumper); use File::Spec; use Digest::SHA qw(sha256_hex); print join("\n", @ARGV),"\n\n"; #print Dumper \@ARGV; my $dir = $ARGV[0]; my $url = $ARGV[1]; my @array; opendir DIR, $dir or die "cannot open dir $dir: $!"; while(my $file = readdir DIR) { next unless(-f "${\File::Spec->catfile($dir, $file)}"); next if("$file" =~ m/^\./); print "${\File::Spec->rel2abs($file)}\n"; my %hash = ( path => File::Spec->rel2abs($file), size => -s $file, id => sha256_hex($file), ); push(@array, \%hash); } closedir DIR; print Dumper sort \@array;
URI escape Chinese characters on file download
1 direct reply — Read more / Contribute
by hankcoder
on Dec 07, 2017 at 16:08

    This URI escape for Chinese character has being bugging me for quite sometime.

    I have a filename saved in my data with mixed letters so as Chinese characters in base64 encoded. However, when I execute a file Download request, I unable to get the save file to appear back to original Chinese characters filename. I'm not sure if it can be done or not. For now, they are all in standard uri_escape.

    I also tried using uri_escape_utf8 result still same. It will become something like "...chinese%20%27%E9%A1%B6%E9%A1%B6.....png". The original Chinese filename is "chinese '顶顶顶顶' & 123.png" just for testing.

    In download script;

    use URI::Escape; .... $fname = uri_escape($fname); .... print "Content-length: $fsize\n"; print "Content-Disposition: attachment; filename=$fname\n"; print "Content-Type: application/force-download;\n\n"; ....

    The download script works fine. Just when download file that contain Chinese characters filename, I can't get it Save in Chinese characters. The filename stored in my data base64 are decoded properly.

    Could someone please give me some suggestions or that is just the way how it works? Many thanks.

Guidelines for listing functions/methods in POD?
7 direct replies — Read more / Contribute
by Dallaylaen
on Dec 07, 2017 at 15:34

    Hello dear esteemed monks,

    Having published some modules, I finally started wondering about formatting function names

    For some reason, cannot even recall why, I began documenting my modules' functions using a header with usage example:

    =head2 frobnicate( $foo, $bar )

    Now it looks rather cumbersome to me, so I'm leaning towards

    =head2 frobnicate =over =item frobnicate( $foo, $bar ) =item frobnicate( \%baz ) =back

    But I see that many CPAN authors go even further and remove functions/methods from index altogether, leaving only

    =item frobnicate()

    I for one prefer more structured documentation. Where can I find guidelines for doing it properly? What are the reasons for and against each practice? At least Test::Pod::Coverage permits all three...

    Oh, it looks like I'm sold on the second variant: after re-reading perldoc perlpod it turns out that sections are linkable via L<Foo::Bar/frobnicate>. Still posting this, there sure is something to add to my thoughts!

Single sign on with AD
2 direct replies — Read more / Contribute
by newbie200
on Dec 07, 2017 at 10:45

    Hello, I am currently new to perl. I am trying to implement sso on a perl web app but don't seem to get my head round it. here are the technical details

    on apache i downloaded, installed and configured the mod_auth_sspi.so module. this allowed me to detect a user logged on a computer, I was able to know if the user was in a local domain or global domain. now comes the tricky part. i have to program in my web app an sso which sees the person logged on from apache. I also have ldap configured. It just seems so confusing to me

    I would be glad if someone can explain more on this. do i need an sso server? how do i connect my perl webapp to read my apache and get the information required.
Compare each array element to the rest, sequentially
4 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 07, 2017 at 09:54
    Dear Monks
    if you build an array, say with the following snippet:
    $file=$ARGV[0]; @all_IDS=(); open IN, $file; while(<IN>) { chomp $_; push @all_IDs, $_; } close IN;

    What I want to do is to calculate the Levenshtein distance between each element and all the rest in the array.
    If I have only 2 IDS, it is easy:
    use Text::Levenshtein qw(distance); $distance = distance ($id1, $id2);

    What must I write in order to sequentially grep each of the IDS and then compare it to the rest? With slice I guess I would remove it and I do not want that, maybe slice and push once I am done? Something smarter?
Executabel PAR package and write protected folders
1 direct reply — Read more / Contribute
by malus_bird
on Dec 07, 2017 at 06:44

    Hi out there!

    I'm a per novice and just a user of the windows version of exiftool, that comes as a executable PAR package.

    When executed the first time it unpacks into a par folder in my temp folder and then executes another exiftool.exe that's unpacked into this folder. The temp folder is of course writeable by the login in user.

    But I'm on a computer with Microsofts "Software restriction policies" that does not allow to execute programs from writeable folders.

    I tried moving the par folder to write a protected folder and set a var. This was the result:

    >set PAR_GLOBAL_TEMP="C:\Program Files (x86)\Tools\par" >exiftool exiftool: creation of private cache subdirectory "C:\Program Files (x8 +6)\Tools\par" failed (errno= 22)
    It seems exiftool still needs write access to this folder although all needed files already exist.

    Any ideas how to solve this?

    Thanx for reading,


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (2)
    As of 2017-12-12 05:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (326 votes). Check out past polls.

      Notices?