Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Nov 8, 2024
1 parent e34efc0 commit e31f57a
Show file tree
Hide file tree
Showing 43 changed files with 1,011 additions and 43 deletions.
62 changes: 61 additions & 1 deletion sites/en/pages/how-to-rename-multiple-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=indexes Path::Tiny, Path::Iterator::Rule
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -55,3 +55,63 @@ name and building the new name.

Some commented out print-statement were left in, to make it easier to follow what's happening.

<h2>Comments</h2>

This code appeared a short path to my desired goal, but also seems to confuse the target directory with a package name:

D:\usr\crt\src\perl>perl rename_0.pl D:\usr\home\img\crocus\try
Can't locate object method "basename" via package "D:\usr\home\img\crocus\try" (perhaps you forgot to load "D:\usr\home\img\crocus\try"?) at rename_0.pl line 14.

What have I mangled?

---
Disqus seems to hide your source code. Try to post the source code on https://gist.github.com/ and then include the link to it here.
---
Gabor --

Thanks for quick response. No, Disqus indeed shows the command dialog that I posted. Here, however, is the source code, where I only hardwired the target directory, instead of using an inline argument:

use strict;
use warnings;
use 5.010;

# (change multiple filenames perl)
# //perlmaven.com/how-to-rename-multiple-files
# Cmd line: perl rename.pl path/to/dir.
# OR: replace "my $dir ..." with "my $dir = "/full/path/to/dir";"
# then run without passing the directory-name argument

my $dir = "D:/usr/home/img/crocus/try";
# my $dir = shift or die "Usage: $0 DIR";

use Path::Iterator::Rule;
use Path::Tiny qw(path);
my $rule = Path::Iterator::Rule->new;
my $tgt = "IMG_20170303_";

for my $file ($rule->all($dir)) {
# say $file;
my $pt = path $file;
say $file->basename;
if ($pt->basename =~ /$tgt/) {
my $newname = $pt->basename;
$newname =~ s/$tgt//g;
say "rename " . $pt->path . " to " . $pt->parent->child($newname);
rename $pt->path, $pt->parent->child($newname);
}
}
---
You probably wanted to write $pt->basename; instead of $file->basename; in the line that gives you the trouble.
---
Gabor -- Yep, that did it. Thanks. You may want to change that offending 'say in your example at line 14 -- slipped right by me.
---
Oh there was a bug in the example. I see. Fixed now. Thanks for mentioning.
---
Gabor -- Thanks again. Now that it's working, I realize that I really want to process just one directory, no iteration. What's the easy/right way for that? The iterator's depth rules seem promising:

$rule->min_depth(0);


But is Path::Iterator::Rule the wrong tool in the first place?
---
Use the built-in glob function of Perl.
18 changes: 17 additions & 1 deletion sites/en/pages/how-to-run-a-perl-script-automatciall-every.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=indexes cron
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -66,4 +66,20 @@ MS Windows has a service called
<a href="https://docs.microsoft.com/en-us/windows/desktop/taskschd/task-scheduler-start-page">Windows Task Scheduler</a>. Use that.


<h2>Comments</h2>

How to run the written Perl program for every 1 hour in Windows? I need to take back up of files for every one hour. Please help.

Look for the Windows Task Scheduler: https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page

<hr>

Hi Gabor,
Few doubts want to get off.
1) why can't we write 0 1 * * * command to run for every hour instead code line you provided.
2) When I tried to replicate same code and tried to run corntab.txt by source command . I got error saying that 0 command not found so is there any header file to include before these set of lines. can you please help me in this.

---

1) That's the same I wrote with different numbers
2) Then you might have done something else not what I wrote
18 changes: 17 additions & 1 deletion sites/en/pages/how-to-sort-a-hash-of-hashes-by-value.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=indexes hash, keys, values, sort, cmp, <=>, $a, $b
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -126,4 +126,20 @@ Gaur 2
Of course if, we encounter two entries where both the <b>Position</b> and the <b>Max</b> fields have the exact same value,
then even this sort won't provide the same results on every call.

<h2>Comments</h2>

Hi, I have created several Hash
$PV_2{$JOB}=$PV_2;
$PV_3{$JOB}=$PV_3;
$PV_4{$JOB}=$PV_4;
$PV_5{$JOB}=$PV_5;
and I know the key name I would like to retrieve the data for in this case PV_5
$PV="\$PV_5";
$geoff=$PV{$JOB};
but how do I get this statement to work as $PV is not resolved to $PV_5

---
It seems $PV_2{$JOB}=$PV_2; that you have both a $PV_2 scalar and a %PV_2 hash here. That's not a good idea for start.
It is also unclear to me why do you have escaping on the $ sign in $PV="\$PV_5"; The key probably does not contain $, it is in the variable $PV_5, right?

This does not seem to be the whole code, could you share a bit more that also shows the "use strict" part and the declaration of the variables.
7 changes: 6 additions & 1 deletion sites/en/pages/how-to-write-to-the-beginning-of-a-file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=status show
=author szabgab
=archive 1
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -49,3 +49,8 @@ you can use <a href="https://metacpan.org/pod/Path::Tiny">Path::Tiny</a> to make

<include file="examples/prepend_with_path_tiny.pl">

<h2>Comments</h2>

Thanks a lot for this useful codes. One question of a beginner: using second version of the code (tiny) at the end of each line I got ^M. I think this has to do with Windows and defines end of line. Interestingly, using the first code (without tiny) after the second version the ^M disappears. So, I'm wondering if there is a way using second version of the code and omitting ^M.


2 changes: 1 addition & 1 deletion sites/en/pages/immediate-writing-to-files-flushing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=status show
=author szabgab
=archive 1
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=indexes cpanm, App::cpanminus, local::lib
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down
4 changes: 3 additions & 1 deletion sites/en/pages/introduction-to-regexes-in-perl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=status show
=books beginner
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -128,3 +128,5 @@ So when you feel it is hard to understand a 20-character regex, compare that to
The other is that if you follow the Perl Maven articles and do the exercises, <b>you will learn how to read and understand regexes</b> and you won't have
a problem dealing with regexes any more.



2 changes: 1 addition & 1 deletion sites/en/pages/is-this-ip-in-the-given-subnet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=tags screencast
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down
6 changes: 5 additions & 1 deletion sites/en/pages/join.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=status show
=books beginner
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -39,4 +39,8 @@ list and the elements will be glued together with the given "connector".

This "connector" can be any string, even the empty string.

<h2>Comments</h2>

Addition: you can also feed 'join' a list, as is shown here: https://perlmaven.com/sorting-mixed-strings

Thanks this is what i was looking for!
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=status show
=books metacpan
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -132,3 +132,13 @@ plugins for <a href="http://perldancer.org/">Perl Dancer</a>, or <a href="http:/
or for any other module on CPAN.


<h2>Comments</h2>

hi, im developing a proyect using perl but ive been experiencing some trouble when i try to verify if the module is installed. the module giving me trouble is File::Basename, i install it by running the following commands: ./Configure -des -Dprefix=$HOME/localperl
make test
make install.
thats what the README file sayis i need to run to install the module and a did it but when i try to verify if the module is really installed using: perldoc File::Basename it says: No documentation found for "File::Basename".

File::Basename is a standard module. If you have perl installed you should already have it. Have you tried actually using the module? What OS do you use?


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=tags screencast
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down
23 changes: 22 additions & 1 deletion sites/en/pages/logging-with-log4perl-the-easy-way.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=tags screencast
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -128,3 +128,24 @@ $logger->debug( "This is debug");
$logger->trace( "This is trace");
</code>


<h2>Comments</h2>

where does logger log to...I mean there must be a file where all all these logging message is stored.

see https://search.cpan.org/~mschilli/Log-Log4perl-1.49/lib/Log/Log4perl.pm#Initialize_via_a_configuration_file

It's done in a configuration file that you setup and use:

use Log::Log4perl;
Log::Log4perl->init("log.conf");

<hr>

How can we trace back the log file, I mean where exactly these errors will be stored?

<hr>

hey,
the variable $WARN has to be set to Log::Log4perl::Level::to_priority( 'WARN' ) ?

13 changes: 12 additions & 1 deletion sites/en/pages/loop-controls-next-last.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
=books beginner
=author szabgab
=archive 1
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -70,3 +70,14 @@ It skipped all the lines that did not start with DNA: and once it found a match

Calling <hl>redo</hl> will execute the current iteration again without checking the condition. I don't recall using it
so let's not get into it now.

<h2>Comments</h2>

I was expecting something on the "continue" keyword, which is actually useful in some cases. There's a good example on the "eof" doc page (https://perldoc.pl/function....

I find "continue" useful when parsing files, and I need to deal with line numbers. Also, when there's some work that needs to be done between iterations, but "next" or "last" is used a lot, "continue" can be more obvious and maintainable.

"redo" is also useful sometimes, when external state changes, or IO is needed.

---
When I wrote this I was more focused on the idea that people new to perl would want to use the "continue" keyword they know from other languages and I wanted to direct them to the "next" keyword.
8 changes: 7 additions & 1 deletion sites/en/pages/lvalue-substr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=indexes substr, Lvalue
=status show
=author szabgab
=comments_disqus_enable 1
=comments_disqus_enable 0

=abstract start

Expand Down Expand Up @@ -63,4 +63,10 @@ you can use <a href="/perl-critic-one-policy">Perl::Critic</a>, and make sure th
<a href="https://metacpan.org/pod/Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr">ProhibitLvalueSubstr</a>
policy is enabled.

<h2>Comments</h2>

parameter 4 not taking variable as input in substr function in v5.22.1. any alternate way to do the same?

Could you give an actual example of the problem you face?

thanks for the quick response. I found another bug in my code. substr function works completely fine. thanks once again, inconvenience regretted.
Loading

0 comments on commit e31f57a

Please sign in to comment.