Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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
(SOLVED) How do I display only matches
3 direct replies — Read more / Contribute
by tem2
on Sep 23, 2019 at 20:34
    use strict; use warnings; my $filename = 'file.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { chomp $row; print "$row\n"; }

    I'm not sure how to close the thread and I don't want to commit any mortal sins, so I'll edit my original post with closing remarks. When I turned on "show all symbols" in my input file, there was no space preceding the CRLF. All is well now. Thanks to everyone.

    I am a beginner. The code above will display the contents of file.txt. I want to only display records which match the regular expression: /.{54}\\a-zA-Z\s\r\n/g Thank you for any assistance.

HTTP::Tiny status 403
2 direct replies — Read more / Contribute
by leosole
on Sep 23, 2019 at 18:01
    Hello, I'm trying to use HTTP::Tiny to get the html of a web page, but I'm getting a 403 Forbidden status. Am I doing something wrong?

    This is my code:

    use strict; use warnings; use HTML::TreeBuilder; use HTTP::Tiny; use Data::Dumper qw(Dumper); use IO::Socket::SSL; my $link = 'https://www.tudogostoso.com.br/receita/199993-bolo-de-lima +o.html'; my $response = HTTP::Tiny->new->get($link); my $html; print "$response->{status}\t$response->{reason}\n"; print $response->{content}; if ($response->{success}) { $html = $response->{content}; print "entrou\n"; }
    And the prints:
    403 Forbidden <html><head><title>You have been blocked</title><style>#cmsg{animation +: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}} +</style></head><body style="margin:0"><p id="cmsg">Please enable JS a +nd disable any ad blocker</p><script type="3cc341b69494194c916377bc-t +ext/javascript">var dd={'cid':'AHrlqAAAAAMAn9GuxP5ZUjsAut-v0g==','hsh +':'C499C5254821BA7F386B459241B3FC','t':'fe'}</script><script src="htt +ps://ct.datado.me/c.js" type="3cc341b69494194c916377bc-text/javascrip +t"></script><script src="https://ajax.cloudflare.com/cdn-cgi/scripts/ +95c75768/cloudflare-static/rocket-loader.min.js" data-cf-settings="3c +c341b69494194c916377bc-|49" defer=""></script></body></html>
Script created html page won't run a perl script
3 direct replies — Read more / Contribute
by lmck21
on Sep 23, 2019 at 16:10

    I have a perl script that creates an html page (www.curb-king.com/buildcurbpackage.htm - runs buildquote.pl). www.curb-king.com/cgi-bin/buildquote.pl has a couple of links that run perl programs. I get errors in the browser when I run those scripts. (chrome : website didn't send any data, firefox -the connection to the server was reset while the page was loading) If I type the address into the browsers directly it works (http://www.curb-king.com/cgi-bin/sendquoteemail.pl).

    I developed this script on a computer I have set up to test scripts using lighttps and it worked fine. But I am having problems when I uploaded it to the server. Any thoughts, work arounds or better ways to do it.

    Thanks

Email::Folder::Exchange and basic authentication
1 direct reply — Read more / Contribute
by TieUpYourCamel
on Sep 23, 2019 at 14:22
    Microsoft says basic authentication will be disabled on Office365 in October 2020. Looking at Email::Folder::Exchange, it doesn't say if it uses basic authentication or not. I assumed it did though, and if you pry into the soap object from Email::Folder::Exchange:EWS, it seems that it does:
    use warnings; use strict; use Email::Folder::Exchange::EWS; use Data::Dumper; my $folder = Email::Folder::Exchange::EWS->new('https://outlook.office +365.com', 'myemail@address.com', 'mysupersecurepassword'); print Dumper $folder->soap();
    snippit of results:
    'basic_authentication' => { 'outlook.office365.com:443' => { '' => [ 'myemail@address.com', 'mysupersecurepassword' ] } },
    Where can we go to see if any changes to the module are in the works? I have several instances of this module in production use and I'm hoping not to have to rewrite them too much.
Duplicate variable returned from sub
2 direct replies — Read more / Contribute
by Zenzizenzizenzic
on Sep 23, 2019 at 12:44
    Looking at old cold, I'm seeing some lines like
    my ($var1, $var2, $var3, $var1) = someFunction($var4);
    Since the $var1 is declared twice, use warnings; flags it. I assume the latter instance will be the one kept, but is this correct? Thank you
[SOLVED] Win32::GuiTest::SendMessage/AllocateVirtualMemory and TCHAR**
1 direct reply — Read more / Contribute
by pryrt
on Sep 23, 2019 at 11:56

    Monks,

    As I started talking about a couple months ago in the Notepad++ Community forum, and mentioned recently in another post there, I'm working on a library that will allow an external perl instance (ie, not via a plugin) to use Win32::GuiTest::SendMessage to control Notepad++.

    For communicating with Notepad++ itself, I've got most message-types (sending messages, getting back return-values and lParam [out] values, including sending or receiving a single string). I believe there's only one more type of wrapper I need: the interface to allow wParam to be a TCHAR** (in or out; since it's a **, if I can get one working, I should be able to get both), which is required for NPPM_GETOPENFILENAMES and related (1), and for NPPM_GETSESSIONFILES and NPPM_SAVESESSIONS (2)

    (1: okay, techincally, I have a workaround for GETOPENFILES: I manually loop through the open buffers, and do single-filename-reads instead.)

    (2: For NPPM_SAVESESSIONS, it actually requires wrapping it in a struct; but I think if I can make the TCHAR** work, then wrapping a struct around that should be doable. At least, once I have the technique, I'll have a technique, and I have this as a guide for how to do a struct.)

    If I were in a plugin directly, and thus had access to the parent process memory space, in a C-like language, I could just define the wParam as a TCHAR**, and it would just work -- there are plenty of instances on github of plugins doing that, and I could have just translated those into the Perl equivalent. Unfortunately, because I'm in an external process, I have to use VirtualAllocEx and friends (as mentioned). As I said above, I was able to figure out enough of VirtualAllocEx (and its the Win32::GuiTest wrapper of AllocateVirtualBuffer) to get it to pass a single TCHAR* string back and forth. But I haven't been able to implement the TCHAR** the way I understand -- all I can read back is a string full of NULL \0 bytes.

    My example code, which shows working Perl for a normal string, and my NULL-only result with TCHAR**:

    Unfortunately, I'm out of ideas, so I'm asking in both the Notepad++ Community and in perlmonks. If there's someone that can show an external C example using VirtualAllocEx or an external Perl script using Win32::GuiTest::AllocateVirtualBuffer, and successfully talk with Notepad++'s NPP_GETOPENFILENAMES message, I'd appreciate it.

    (I know @ekopalypse in the Notepad++ community has shown some facility in hopping back and forth between languages... and vr in perlmonks has the only recent post on perlmonks involving AllocateVirtualBuffer... but I'm definitely not limiting my request for help to just those two.)

    crosslinks:

    edit: fixed link once I had the post actually made in the Community. Sorry for the two minutes when I didn't have a URL yet. I tried a stealth edit, but you guys started reading too fast. :-)

Tk Entry and ListBox width
1 direct reply — Read more / Contribute
by Anonymous Monk
on Sep 23, 2019 at 05:45

    Dear monks

    I thought it should be easy to achieve this...but after reading both Entry and ListBox PODs I could not found any solution. I am creating a mega widget with an Entry and a ListBox. What I need is to get the size (better in pixels, but characters would go too) and set the same width to the ListBox.

    I seem to fail already by the first task, reading the width of the Entry. A simple

    $EntryWidget->cget('-width');

    Does not seem to help. I have the impression I get a standard "20" which may be the value at creation time (but not the real width of the widget which is managed by pack).

    Maybe this task cannot be achieved, or maybe I am looking at the wrong approach. Any suggestions will be appreciated.

vars in use and require
3 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 21, 2019 at 17:33
    I thought it would be neat to use the perlver module to automatically detect and "use" the minimum version of Perl. But "use" does not seem to accept variables (tried many ways), while "require" takes vars but "Can't locate 5.nnn in @INC". Is this sort of thing even possible? Thanks
    #!/usr/bin/perl use strict; use warnings; BEGIN { goto DONE unless eval { require Perl::MinimumVersion }; my $v = Perl::MinimumVersion->new(__FILE__); $v = $v->minimum_version; # use $v; # no way jose, can't eval either # require $v; # Can't locate 5.nnn in @INC # warn $v; # FYI DONE: }
Can a Perl module "inspect" itself and provide details about methods and parameters?
7 direct replies — Read more / Contribute
by Br'er Rabbit
on Sep 21, 2019 at 16:34

    I'm suffering through an exercise to do some image processing with ImageMagick by way of PerlMagick (the Image::Magick Perl module).

    The documentation is maddening (notwithstanding RLS's praise of it as "unimpressive"), and anyone who wants to do anything other than a simple example, will find theirself roundtripping from pillar to post.

    Until reading his comment, I hadn't thought to look at the--shudder--source code,

    ...but my thoughts were running a different direction.

    I seem to remember that Perl modules are "objects" or collections of them and I remember from the many attacks on my comprehension by "object-orientation" that "objects" can be ASKED this-or-that. (It's supposed to be a "feature.")

    I also recall that they implement METHODS which can be public or private to make answer to queries.

    And so...

    ...SINCE "objects" and "Perl modules" are way smarter than me, knowing way much more about their innard-parts than me, I would like to ask them:

    "Hey, could you please TELL me what PUBLIC methods you have, and WHAT parameters they use, including their DEFAULTS?"

    Kinda like: "Hey, why don't you read your own damn source code and highlight the most important bits for me?"

    If they would just do that, I would write their answers down and tape them to the stupid monitor and stop all this hunting around.

    Thank you for your time. Peace.

detecting an undefined variable
8 direct replies — Read more / Contribute
by LloydRice
on Sep 21, 2019 at 08:41

    How do I detect whether a variable has been defined in an enclosing context? I tried

    my $myscale = 1; if ( defined $scale ) { $myscale = $scale; }
    When $scale does not exist in the outer context, this fails. So then I tried
    my $myscale = $scale // 1;
    with the same result. But "defined" seems to want an existing object (function, array, etc.), So finally, I tried it this way ..
    my $myscale = extscale // 1; sub extscale { return $scale; }
    I have reread the Camel sections on "defined" and "exists". Neither of these does what I am looking for. Is there some way to do this?


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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2019-09-24 08:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The room is dark, and your next move is ...












      Results (290 votes). Check out past polls.

      Notices?