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

All hail ye PerlMonk Gods ... May I be so bold as to put forth a question seeking knowledge?

What does

. "$1"

mean when it is the first line in a perl script?

I would guess it means this:

$_ = $_ . "$1"

where $_ is the default perl variable

and

$1 is the match/capture group 1

But, that makes no sense as the first line. So, what gives?

Thanks in advance!

Replies are listed 'Best First'.
Re: . "$1"
by bliako (Abbot) on Aug 24, 2018 at 00:28 UTC

    You assumed the file contains Perl code. Are you sure? I mean are there more lines further down to look and smell like Perl?

    In a unix shell like sh or bash (and possibly others) the . (the dot) is an alias for source which executes the contents of a file in the current shell using the current shell as the interpreter. While $1 is the first argument to the command. So, . "$1" in sh/bash means source the file named by the first argument of this command. And the quotes will make it immune to spaces in the filename.

    example:

    xx.sh:

    # file xx.sh # allegedly perl script . "$1"

    yy.sh:

    # yy.sh a sh script to be executed echo "hello there i am calling from within yy.sh"

    and in a shell:

    $ chmod 755 xx.sh $ xx.sh yy.sh hello there i am calling from within yy.sh

    bw, blako

Re: . "$1"
by hippo (Archbishop) on Aug 24, 2018 at 08:10 UTC

    Try it and see:

    $ perl -e '. "$1"' syntax error at -e line 1, near "." Execution of -e aborted due to compilation errors.

    So, as everyone else has hinted, it isn't valid Perl.

Re: . "$1" (updated)
by AnomalousMonk (Archbishop) on Aug 23, 2018 at 23:29 UTC
    What does   . "$1"   mean when it is the first line in a perl script?

    If that's really absolutely all there is on the first line, it means the file containing the script has been corrupted; characters have been lost off of the beginning (at least!) of the file. (Update: Of course, this assumes the script is (or was) Perl to begin with. Others have suggested this code fragment is a piece of a shell script, and this seems much more likely to be the answer!)


    Give a man a fish:  <%-{-{-{-<

Re: . "$1"
by LanX (Saint) on Aug 23, 2018 at 22:45 UTC
    Looks like a syntax error for me. This compiles?

    The only way to make this work might be a code transforming option from perlrun

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice