Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

runtime error not caught by compilation check???

by ww (Archbishop)
on Dec 26, 2016 at 03:01 UTC ( [id://1178494]=perlquestion: print w/replies, xml ) Need Help??

ww has asked for the wisdom of the Perl Monks concerning the following question:

Problem (between my ears, no doubt): a runtime error not caught with perl -c FN:

C:\>perl -c D:\_STM_work\htmFROMstm16(sms+).pl D:\_STM_work\htmFROMstm16(sms+).pl syntax OK C:\>D:\_STM_work\htmFROMstm16(sms+).pl Global symbol "$skedhash" requires explicit package name (did you forg +et to declare "my $skedhash"?) at D:\_STM_work\htmFROMSTM16.pl line 65. BEGIN not safe after errors--compilation aborted at D:\_STM_work\htmFROMSTM16.pl line 66.

code (irrelevant lines redacted for brevity):

#! /usr/bin/perl use warnings; use strict; use feature qw'say'; use DBI; my ($link_id, $events_item, $events_type, $events_longdesc, $starttime +, $endtime, $location, $who, $note, $extra, %skedhash, $skedhash); # %skedhash &amp; $skedhash declared! my $FH_out; # get data from db # LN12 ... (irrelevant) $select->execute or die $DBI::errstr; # Create html #LN27 # ... (irrelevant) sub sked { #LN44 no warnings "uninitialized"; %skedhash = @_; say "In sub 'sked'"; say "LN50: \$link_id, \$events_item, \$events_type, \$starttime, \$endtime, \$location, \$who, \$note, \$extra: $skedhash{'li +nk_id'}, $skedhash{'events_item'}, $skedhash{'starttime'}, $skedhash{ +'endtime'}, $skedhash{'where'}, $skedhash{'who'}, \n $skedhash{'note'}, +\n $skedhash{'extra'} $skedhash{'events_longdesc'} \n"; if ($skedhash{'who'} ne '') { $skedhash{'who'} = 'Hosted by ' . $skedhash{'who'}; } print $FH_out "<tr> <td><b>$skedhash{'$events_item'} </b> <i>$skedhash{'$events_type'} </i> $skedhash +{'who'}<br> $skedhash{'starttime'} - $skedhash{'endtime'} $skedhash{'location'} </td> <td><b>$skedhash{'events_longdesc'}</b></td> </tr>"; use warnings "all"; } ### END sub sked() ######## my $sql = qq/SELECT events.link_id, events.item, events.type, events.l +ongdesc, times.starttime, times.endtime, times.location, times.who +, times.note, times.extra FROM events, times WHERE events.link_id = times.link_id ORDER BY starttime/; # LN65 my $sth = $db->prepare($sql); # LN66 $sth->execute(); while ( my ($events_link_id, $events_item, $events_type, $events_longd +esc, $starttime, $endtime, $location, $who, $note, $extra) = $sth->fetchrow_array ) { my %skedrow = ( 'events_link_id' => $events_link_id, 'events_item' => $events_item, 'events_type' => $events_type, 'events_longdesc' => $events_longdesc, 'starttime' => $starttime, 'endtime' => $endtime, 'location' => $location, 'who' => $who, 'note' => $note, 'extra' => $extra ); ....

Maybe it's too much Christmas cheer, but the headache here is too early to be a hangover.

check Ln42!
But I did!!!

Replies are listed 'Best First'.
Re: runtime error not caught by compilation check???
by LanX (Saint) on Dec 26, 2016 at 03:27 UTC
    Why do you call

    D:\_STM_work\htmFROMstm16(sms+).pl

    with (sms+) but errors display

    D:\_STM_work\htmFROMSTM16.pl line 66.

    without ? ? ?

    Edit:

    I'm confused about your shebang on windows and I wouldn't be too surprised if this is not the code which is actually run.

    Maybe try

    perl.exe D:\_STM_work\htmFROMstm16(sms+).pl

    or

    perl -c D:\_STM_work\htmFROMSTM16.pl

    and see what happens. :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re: runtime error not caught by compilation check???
by ww (Archbishop) on Dec 26, 2016 at 14:37 UTC

    Thanks to all who took their time to try to help; especially since my OP does NOT provide an SSCCE nor all the other info that would be helpful. So...

    Replying to the questions above in the order they were asked.:

    1. LanX: Execution and error names not match?
      ww: I have no clue but assure you, that's exactly what's happening. FWIW, there has not been a file with the name in the error on my machine since shortly after it was created and failed. (Yeah, I know, I should use some sort of version control. Bad on me!)
    2. LanX: shebang....
      ww: For all practical purposes, windoze ignores that shebang, but ultimately, execution will be on a Linux box (Apache).
    3. LanX: try....
      ww: Good thought, but basicly, I couldn't do that. see first ww reply.
       
    4. beech: use code on PM site? (1)& (3) "$select" error
      ww: Great idea, but failed because I'd removed too much code in effort to be (most of) SSCCEE.
      However, after downloading the PM code and restoring what I'd removed, I found a what I think was one problem; the quoting at what became line 50 was INCORRECT. It used single quotes inside the curlies, rather than escaped double quotes.
      beech: 2: vers?
      ww: 5.24, ActiveState, on dev box, Win7 pro (which harbors an evil spirit of some sort; see first reply to LanX.)  
       
    5. Marshal: (as ww understands question) re "invalid statement before the skedhash assignment"
      ww: Some fields in the db are null; I got tired of double checking which were generating the warnings.
      And if the discomfort is about the %skedhash = @_, the sub is being passed a hash, %skedrow.

    I hope I've also learned something else: Don't post a question at near-midnite, Christmas nite (or any other nite). Sleep on it! I suspect (suspect!) I have now solved the actual-misleading-weird-messages-issues with your help and a variant of the teddy-bear method. Again, thanks, and when I'm confident of the solutions, I'll update with (too much) actual, working code

    ++$anecdote ne $data


    check Ln42!

      > ww: For all practical purposes, windoze ignores that shebang, but ultimately, execution will be on a Linux box (Apache).

      IIRC there are various methods on Win to associate script-files to a executable (and none is default) ...

      > ww: 5.24, ActiveState, on dev box, Win7 pro

      ... so probably you should check if you have multiple Perl installations on your machine.

      Try to run the code directly with the same perl.exe which was used for the syntax check and see if the errors still differ.

      update

      Probably you want to prepend this to your script

      BEGIN { warn "Exe:$^X , Ver:$^V , File:$0" }

      and compare the outcome in your different runs.

      See perlvar for details

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re: runtime error not caught by compilation check???
by beech (Parson) on Dec 26, 2016 at 03:29 UTC

    Hi ,

    Can you reproduce the error if you download your code from here on perlmonks?

    What perl version are you using?

    On my machine it only complains about $select

Re: runtime error not caught by compilation check???
by Marshall (Canon) on Dec 26, 2016 at 03:44 UTC
    I normally do not declare different types of variables with the same name, eg,  %skedhash, $skedhash, but that is what it is (and completely allowed in Perl).... what is happening here?:
    sub sked { #LN44 no warnings "uninitialized"; %skedhash = @_; say "In sub 'sked'"; #LN44
    That looks like an invalid statement before the skedhash assignment. Could be a problem?

    Update: Maybe that is ok? Not sure since I cannot run the program or see the line that the compile fails at (what is line 65?).

Re: runtime error not caught by compilation check???
by ww (Archbishop) on Jan 01, 2017 at 12:48 UTC

    Warning to readers: What follows is nowhere near "best practice;" in fact, it's not even "good" code. But, FTR:

    The working (but still in need of refactoring) code is much too long to post except in the following readmore but that's why that markup exists. Also noted, failed-currying the raw submissions into a useable form helped masked my mistakes, but the chief issue was hidden in my omissions in the OP.
    Also, FWIW, both with the broken code and the working script, the BEGIN block suggested by LanX produce this

    Exe:C:\Perl\bin\perl.exe , Ver:v5.24.0 , File:D:\_STM_work\1230db2htmWithDblQuotes.pl

    As the filename above suggests, sqlite's norms for quoting (and my departures therefrom) created some of the issues which delayed this update.

    The code producing html output follows inside the 'readmore'; the db-creation-code follows.

    For the record, the cleaned-up data got spewed into the db, this way:

    And, for those who are wondering 'why is that idiot working so hard on producing correct input and output for an event that's gone by? .... well, I've been asked to take over producing the sked and wanted to produce future editions using a db and Perl rather than simply trying to stuff new data into the previous .php (multi-thousand-line) implementation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1178494]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-29 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found