Confusion over the syntax of the dimond operator in perl analysis and simple words

I am very new to perl, so I am sure that my confusion here is simply due to a lack of understanding of the perl syntax and how it handles bare words. I cannot find good answers to my question on the Internet, though.

I had a code that I refactored, it looks like this:

@month_dirs = <$log_directory/*>;

I changed $ log_directory to load the configuration file (more precisely, AppConfig). Now, instead of exporting $ log_directory, we print $ conf, which is an AppConfig object. To access loadable variables, you usually call a method call on the variable name, so I tried ...

@month_dirs = <$conf->log_directory()."/*">

This fails because I cannot make a call to the $ conf-> log_directory method where the barrier is expected. Just playing, I tried this instead

 $month_directory_command = $conf->log_directory()."/*";
 @month_dirs = <$month_directory_command>;

- , - , . , , -, , , , , , , Barewords , , , ?

,

 $month_directory_command = $conf->log_directory();
 @month_dirs = <$month_directory_command/*>;

. , , :

 $bare_word = $conf->log_directory()/*

 $month_directory_command = $conf->log_directory();
 $bare_word = $month_directory_command/*;
 @month_dirs = <$bare_word>;     

, ? , ?

perl , , , , .

, - bareword . , , ?

barword , , , , , , , , .

, , , perl? - , ?

+4
3

, <> :

$ perl -E'say for <"/*">'
/bin
/boot
/dev
...

( , - , use strict 'subs';, .)


:

@month_dirs = <$log_directory/*>;

, <> , $log_directory .

:

@month_dirs = glob("$log_directory/*");

:

@month_dirs = <$conf->log_directory()."/*">

, > $conf->log_directory() , .

:

<$conf->

( glob),

log_directory()."/*">

.


:

$month_directory_command = $conf->log_directory()."/*";
@month_dirs = <$month_directory_command>;

,

<$month_directory_command>

readline($month_directory_command)

glob("$month_directory_command")

perldoc perlop:

, , (, $foo), glob .

[...]

, , , , typeglob glob, , globbed, , , . . , <$x> readline() , <$hash{key}> glob().

, ($month_directory_command), .

use warnings 'all'; :

readline() on unopened filehandle at foo line 6.

:

$bare_word = $conf->log_directory()/*;

, ; .

:

$bare_word = $conf->log_directory() . "/*";
@month_dirs = <"$bare_word">;

( $bare_word , .)

, :

@month_dirs = <$bare_word>;

( ) readline, glob, perlop.

, , , glob :

@month_dirs = glob( $conf->log_directory() . "/*" );
+6

, . , , -

$data = <$fh>;

; () readline.

$data = readline( $fh );

@month_dirs = <$log_directory/*>;

. glob , , . glob:

@month_dirs = glob( "$log_directory/*" );

, . , , :

@month_dirs = glob( $conf->log_directory()."/*" );
+4

goblin can only be inside the bracket <>, the syntax inside is the shell syntax, more perl one

# wrong -     
$bare_word = $month_directory_command/*;
# right - star is allowed because it is inside the quote single or double
$bare_word = "$month_directory_command/*";

# star is allowed simply because it is inside the bracket
@month_dirs = <$month_directory_command/*>;
0
source

Source: https://habr.com/ru/post/1621316/


All Articles