Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:34:55+00:00 2026-05-26T07:34:55+00:00

Running this code parsesendnotes.pl #!/usr/bin/perl use strict; use warnings; use Device::SerialPort; use Time::HiRes qw(usleep);

  • 0

Running this code

parsesendnotes.pl

#!/usr/bin/perl
use strict;
use warnings;
use Device::SerialPort;
use Time::HiRes qw(usleep); # For sleep in ms

if ($#ARGV + 1 != 2) {
    print "Usage: $0 port filename\n";
    print "Example: $0 /dev/ttyASM0 money.txt\n";
    exit 1;
}

my $file = $ARGV[0];
my $dev  = $ARGV[1];

if (!-e $file || !-e $dev) {
    print "File or brain not found.\n";
    exit 1;
}

my $arduino = DeviceSerialPort->new($dev);
$arduino->baudrate(9600);
$arduino->databits(8);
$arduino->parity("none");
$arduino->stopbits(1);

require "frequencies.pl";
open NOTES, "$file";

print $frequencies{"LA3"};

while (<NOTES>) {
    chomp;      # No newline
    s/#.*//;    # No comments
    s/^\s+//;   # No leading white
    s/\s+$//;   # No trailing white
    next unless length;
    if ($_ =~ m/^TEMPO/) {
        my $tempo = split(/\s+/, $_, -1);
        print "Tempo is $tempo.";
    } else {
        my @tone = split(/\s+/, $_);
    }
    my $note = $frequencies{$tone[0]};
    my $duration = $tone[1]*$tempo;
    print "Playing $tone[0] (\@$note Hz) for $tone[1] units ($duration ms).";
    while ($note > 255) {
        $arduino->write(chr(255));
        $note -= 255;
    }
    $arduino->write(chr($note));
    $arduino->write(";");
    usleep($duration);
}

frequencies.pl

my %frequencies = (
    "PAUSE" => 0,
    "B0" => 31,
    "DO1" => 33,
    "DOD1" => 35,
    ...
);

I obtain these errors

Global symbol “%frequencies” requires explicit package name at ./parsensendnotes2.pl line 30.

Global symbol “%frequencies” requires explicit package name at ./parsensendnotes2.pl line 44.

Global symbol “@tone” requires explicit package name at ./parsensendnotes2.pl line 44.

Global symbol “@tone” requires explicit package name at ./parsensendnotes2.pl line 45.

Global symbol “$tempo” requires explicit package name at ./parsensendnotes2.pl line 45.

Global symbol “@tone” requires explicit package name at ./parsensendnotes2.pl line 46.

Global symbol “@tone” requires explicit package name at ./parsensendnotes2.pl line 46.

Execution of ./parsensendnotes2.pl aborted due to compilation errors.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:34:56+00:00Added an answer on May 26, 2026 at 7:34 am

    name %frequencies is localized in file frequencies.pl: my lasts until end of block, or end of file.

    A better way would be to remove my and do like this:

    my %frequencies;
    eval { %frequencies = do "frequencies.pl"; }
    # must check $! and $@ here -- see perldoc -f do`
    

    However, an even better way is to use YAML instead:

    freq.yml

    ---
        "PAUSE": 0 
        "B0": 31
        "DO1": 33
        "DOD1": 35
    

    And then

    use YAML qw(LoadFile);
    # ...
    my $data = LoadFile("freq.yml");
    %frequencies = %$data;
    

    As for @tone, $tempo & co, again, my variable scope is limited to {} block. You should do something like

    my $x;
    if (...) { $x = ... };
    

    to make $x accessible outside if.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I an running this code: #!/usr/bin/python coding=utf8 # test.py = to demo fault def
I'm getting an MDA after running this code for the second time in a
I'm running this code and it show the same time but i wanted different
I'm running this simple code: import threading, time class reqthread(threading.Thread): def run(self): for i
While I am running this code it showing me a following error:- Column 'virtuemart_product_id'
I'm running this code in Firefox 11 on Windows 7. (See http://jsfiddle.net/QStkd/ ). $('<div><input
I get a segmentation fault when running this code. Anyone know why? Thanks. #include
Okay so, I'm currently running this code to move a bunch of data from
I'm a beginner with jdbc ... I have a problem running this code :
I'm running this C# code in Visual Studio in debug mode: public class MyHandlerFactory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.