Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Seekers of Perl Wisdom

( [id://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.

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.

Post a new question!

User Questions
try/finally syntax
4 direct replies — Read more / Contribute
by Superfox il Volpone
on Jun 23, 2024 at 08:58
    I'm on perl v5.34.1, with the "try" feature enabled. I still cannot figure out the correct syntax for:
    my $current_directory = getcwd(); try { chdir($working_directory); } finally { chdir($current_directory); };
    This fails with the error:
    syntax error at /script.pl line 56, near "} finally " Execution of /script.pl aborted due to compilation errors.
    ```
Solve IO::Pty warning issues from Net::OpenSSH
2 direct replies — Read more / Contribute
by dkhosla1
on Jun 22, 2024 at 17:30
    Hi,

    I am using Net::OpenSSH, and if providing a password to a connection, it uses the IO:Pty package and gives a warning.

    The connection is successful. The issue seems to be with grantpt()

    WARN: IO::Pty::new:24: IO::Tty::pty_allocate(nonfatal): grantpt(): Operation not permitted

    With debug it shows 'trying grantpt() ...' before this message.

    1) any suggestions on how to have grantpt() be successful or not be attempted?

    2) Or suppress that specific message or worst case suppress all warning messages from IO::Pty (It was suggested that I use '{ no warning; .. } but I don't want to suppress warnings from Net::OpenSSH itself)

    Thanks!
SOLVED:use -d -t -s as script args
1 direct reply — Read more / Contribute
by vincentaxhe
on Jun 21, 2024 at 11:46
    I have script getfiles.pl with code like that
    my %options; getopts("r:", \%options); ... $regex = qr($options{r}); foreach (@files){ my $filepath = $_->[0]; if ($filepath =~ $regex){ push @matched, $filepath; } }
    I run getfiles.pl -r 'python' filelist to filter filepath containing 'python' but I also want to run like getfiles.pl -e '-d' listfile to get files which are dirs or getfiles.pl -e '-s > 100' filelist and more such as -t -M.
    my %options; getopts("e:", \%options); ... $wanted = qr($options{e}); sub getwanted(&@){ my ($wanted, $file) return 1 if $wanted->($file) ... } foreach (@files){ $filepath = $_->[0]; if (getwanted $wanted $filepath){ push @matched, $filepath; } }
    but the subroutine is not good, ask some advice
Can I get the actual error for DBI->execute() ?
4 direct replies — Read more / Contribute
by SergioQ
on Jun 20, 2024 at 21:43

    I have the function below that I use in perl. I build the command elsewhere as it could be a SELECT, INSERT, et al.

    In one instance I am using the function to insert new records into my MySQL table. And generally it works. But occasionally it will fail on an insert, and I was hoping I could find out what the actual reason an insert failed. To be clear I am inserting over a thousand records into this table, and most work.

    I even had my perl script print out the actual command that returns a nil on the result, and then I copy and paste that exact command into MySQL's terminal where it works. So even more reason to get the exact reason it failed.

    I should add that the table has no index, and no unique fields.

    #from elsewhere in my code ... $db=DBI->connect('DBI:mysql:invoices',[username],[password], { RaiseEr +ror => 0, AutoCommit => 1 }); #$rawDB is set to the table name my $insertCommand = "INSERT INTO $rawDB (sheet_no, sheet_name, item, c +oll, roww, category) VALUES ('$currentSheet', '$sheetname', '$cellData', '$curcol', '$curro +w', '');"; my $result = insertItem($insertCommand); #.... sub insertItem { (my $insertCom) = @_; $dbHandle=$db->prepare($insertCom); my $result = $dbHandle->execute(); return $result; }
Undefined address for Socket::pack_sockaddr_in
1 direct reply — Read more / Contribute
by WithABeard
on Jun 20, 2024 at 07:40

    I am using Firefox::Marionette, and it works great (normally), but is now giving this error:

    % perl -MFirefox::Marionette -e 'my $f=Firefox::Marionette->new()' Undefined address for Socket::pack_sockaddr_in at /Users/<user>/perl5/ +lib/perl5/Firefox/Marionette.pm line 7134.

    The line in question is this one:

    $sock_addr = Socket::pack_sockaddr_in( $port, Socket::inet_aton($host) );

    So I'm guessing that Socket::inet_aton($host) is the culprit

    metacpan.org/pod/Socket tells us that:

    ...If passed a hostname that cannot be resolved, returns undef.

    From this I'll assume that the hostname cannot be resolved, but we're not even opening a url yet...

    Testing Socket yields predictable results:

    % perl -MSocket -e'defined (my $a=inet_aton("garbage")) or die"dead"; +print unpack "V", $a;' dead at -e line 1. % perl -MSocket -e'defined (my $a=inet_aton("127.0.0.1")) or die"dead" +; print unpack "V", $a;' 16777343

    It seems to do its job when passed something sensible

    I usually work from home, but today I went in to the office, and got the error.
    Could this be caused by a change in the network?
    I'll know later today if it works at home.

    System details:

    MacOS 14.5
    Apple M2
    perl ver. 5.34.2

    I tried flushing cache with sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, but this made no difference

    I also tried changing the perl version (using plenv), but then I have to install Firefox::Marionette for the new version, and surprise-surprise; installation fails with the same error :p

    Is this the right way to flush DNS on MacOS 14.5?

    How can I find out what is actually passed to inet_aton when it fails?

    What else can I do to debug this?

Data::Dumper print arrays of scalars on one line
4 direct replies — Read more / Contribute
by Danny
on Jun 19, 2024 at 23:06
    Is there a Data::Dumper option to print arrays of scalars on a single line, but everything else with indentation? For example, like:
    $VAR1 = { 'hk1' => 5, 'hk2' => [ [1, 2, 3], [4, 5, 8] ], etc ...
DBI->connect fails
4 direct replies — Read more / Contribute
by Milti
on Jun 19, 2024 at 15:13

    This error returns when Perl script attempts to connect to a known mysql database"DBI connect('membersdb','memeber',...) failed: Access denied for user 'memeber'@'localhost' (using password: YES) at". Why is this happening when 'ALL PRIVILEGES' on the database have been granted to 'member'@'localhost'. The connection can only be made if I use "root' 'root password'. Here is the statement GRANT ALL PRIVILEGES ON `membersdb`.* TO 'member'@'localhost'. What am I missing?

Regular Expression Assistance
3 direct replies — Read more / Contribute
by g_speran
on Jun 19, 2024 at 12:41

    Wondering if someone can put eyes on this and tell me what i am doing incorrectly. I've tried several option but make it worse

    Hoping someone can quickly spot my error.

    i need to get rid of the doublequotes after 'value=' and before '/>'

    Thanks in advance

    my $content = '<entry key="maxcompdatastripe" value="41943040" />'; my $maxreplacement_value = ' "20917520" merge="keep" '; $content =~ s/(<entry key="maxcompdatastripe" value=")[^"]*("\s*\/>)/$ +1$maxreplacement_value$2/g; print "Content: $content\n"; Expected results: <entry key="maxcompdatastripe" value="20917520" merge="keep" /> Actual Results: Content: <entry key="maxcompdatastripe" value=" "20917520" merge="keep +" " />
Failing with ReadData from Spreadsheet::Read and need to find a way to debug
3 direct replies — Read more / Contribute
by SergioQ
on Jun 18, 2024 at 19:17

    Am trying to read an Excel spreadsheet using Spreadsheet::Read

    I've done everything to confirm the file exists, and is a valid file. I've set the file and its directories all to 777. I've downloaded the file from my server to my desktop and verified that it opens up in Excel.

    But in the code below, I am falling when I eval the ReadData method.

    Where I'm stuck is that other that failing on the eval, I don't know if or how to get further data on why Spreadsheet::Read fails with trying to open my spreadsheet.

    If anyone has any experience using this module, I'd appreciate any help.

    Thank you.

    $filename = "R202406181844029040.xlsx" if ($testMode); my ($ext) = "$upload_dir/$filename" =~ /(\.[^.]+)$/; $ext =~ s/\.//g; $ext =~ s/^\s+|\s+$//g; my $book; my $upFilename = "$upload_dir/$filename"; $logger->debug("entering eval with $upFilename "); if (-e $upFilename) { $logger->debug("file exists"); } else { $logger->debug("file DOES NOT exists"); } eval { $book = ReadData ("$upFilename"); 1; } or do { ...handle error here };
Requiring a version
6 direct replies — Read more / Contribute
by choroba
on Jun 18, 2024 at 04:45
    I noticed weird CPAN testers' failures in the last release of Syntax::Construct (5.38.2 without threads on Solaris, 5.38.2 threaded on Solaris, 5.38.0 threaded on Solaris).

    To know more, I released a dev version with a debugging output. It hasn't been tested on the same machines yet, but I've got similar results from 5.38.2 on FreeBSD and 5.38.0 on Linux. It seems that in all these cases, the following line doesn't fail:

    require (0 + 5.040); # Should fail in 5.38.X!

    I contacted the testers, but there has been digital silence so far.

    If you have a 5.38.X installed, would you be so kind and test it for me, too?

    I still fear it's my fault, so here's the line that shows the debugging information. Do you have any ideas?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

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":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-06-24 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.