Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Printing set characters from offset.

by Jalcock501 (Sexton)
on Sep 23, 2013 at 14:35 UTC ( #1055298=note: print w/replies, xml ) Need Help??

in reply to Re: Printing set characters from offset.
in thread Printing set characters from offset.

Well, I did try:

 print{ substr(( my $lines, $schemePOS, 20) and ( my $lines, $abiPOS, 3)); }

But I got the following:
Global symbol "$lines" requires explicit package name at ./ li +ne 27. Global symbol "$lines" requires explicit package name at ./ li +ne 27. Not enough arguments for substr at ./ line 27, near "))"
I'm not even sure if you can do that with the substr method. But as I say I'm not sure of the syntax for it.

Replies are listed 'Best First'.
Re^3: Printing set characters from offset.
by kennethk (Abbot) on Sep 23, 2013 at 14:59 UTC
    A couple issues here.
    1. my is used to declare a lexical variable. In general, my $lines should appear once in your code, when you first use it. If you are going through a file, it might look like:

      while (my $lines = <$fh>) {...
      The text you have written declares two new, undefined variables named $lines.
    2. and is a logical operator. The code you wrote takes two lists (( my $lines, $schemePOS, 20) and ( my $lines, $abiPOS, 3)) and tests if they are both logically true. Since the lists are both longer than 0 elements, and returns a true value, and this true value is then fed into substr, which expects at least two arguments, thus the returned error.

    3. Lastly, print takes a list (parentheses), not a block (curly brackets) as an argument. Either

      print $arg1, $arg2, ...
      or, if you want to have a clear delimiter,
      print($arg1, $arg2, ...)
    The code you meant to write would probably look like:
    print substr($lines, $schemePOS, 20), substr($lines, $abiPOS, 3);
    I have fed print a list of two values, which are the return values of the substrs. There are a number of ways to do this, but they'd all fit this general pattern.

    Given your apparent familiarity with the language, I'd suggest going through some introductory learning materials. has a number of resources available, including free access to Beginning Perl.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re^3: Printing set characters from offset.
by hippo (Canon) on Sep 23, 2013 at 14:57 UTC

    That isn't what the "and" operator does. If you want to print 2 substrings, call substr twice, eg:

     print substr ($lines, $o1, $l1) . substr ($lines, $o2, $l2);
Re^3: Printing set characters from offset.
by Corion (Pope) on Sep 23, 2013 at 14:55 UTC

    Please show a short, self-contained program that exhibits the problem.

    Your code is almost valid Perl, but it is highly nonsensical. Maybe you can explain in English what the characters you wrote are supposed to mean.

    I don't know how to advise you further, other than to learn Perl from a tutorial. You cannot take English sentences and hope that Perl will interpret them as you intend.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055298]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2018-06-22 12:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.