Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Use scalars to define a filename

by Ovid (Cardinal)
on Oct 17, 2011 at 14:13 UTC ( #931935=note: print w/replies, xml ) Need Help??

in reply to Use scalars to define a filename

There are a couple of issues here. First, when you get the "string found or bareword..." error message, it will include a line number. That line number is likely not the line you're pointing to because there are no barewords or syntax errors in the code above. You'll want to post a larger code snippet.

That being said, in Perl an identifier should start with a letter or underscore and is followed by zero or more word characters. A scalar variable in Perl is defined as a dollar sign ($) followed by an identifier. When you have a this line:

my $filename = "fileLocn/$var1_$var2.txt";

When you fix your other issue, you'll probably get an error message similar to: Global symbol "$var1_" requires explicit package name at line 10.

(Note: If you're on a version of Perl less than 5.10, you won't see the variable name)

Perl thinks that $var1_ is a variable name. You need to tell Perl that the trailing underscore (_) is not part of the variable name. You can fix this one of two ways:

# escape the underscore my $fileName = "fileLocn/$var1\_$var2.txt"; # or wrap the identifier in curly braces my $fileName = "fileLocn/${var1}_$var2.txt";

Also, I suspect that you wanted fileLocn to begin with a dollar sign?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931935]
[choroba]: three
[choroba]: I mean I haven't used DBIx::Class nor M:S, only Moo
[1nickt]: Haha, I was learning about Linux filesystem trees trying to understand how Moo fits.
[1nickt]: I just got my feet wet with some DBIC coding this last week. I feel "meh" about it so far. It was pretty easy to add a sub to the DBIC class to filter search results ...
[1nickt]: ... in the calling code ... $rs = $rs->maturity(" stable");. But I don;t enjoy feeling that far away from the SQL and the DB, really.
[1nickt]: The same project (CPAN Testers API) is using experimental signatures (and therefore 5.024) ... which is what replaced Method::Signatures , afaict.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-11-24 13:27 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (349 votes). Check out past polls.