From richard at rushlogistics.com Sat Dec 23 14:57:36 2023 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 23 Dec 2023 17:57:36 -0500 Subject: [Chicago-talk] What does dollar sign followed by a period represent? Message-ID: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> A few years ago I hastily wrote some code that I did not comment very well. In it I found: ?$switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # match date Can anyone tell me what $. means? Thanks for any help. Richard From andy at petdance.com Sat Dec 23 14:59:24 2023 From: andy at petdance.com (Andy Lester) Date: Sat, 23 Dec 2023 16:59:24 -0600 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> Message-ID: <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> It?s the current line number. See ?perldoc perlvar? > On Dec 23, 2023, at 4:57?PM, Richard Reina wrote: > > ? > A few years ago I hastily wrote some code that I did not comment very well. In it I found: > > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # match date > > Can anyone tell me what $. means? > > Thanks for any help. > > Richard > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk From richard at rushlogistics.com Sat Dec 23 15:02:18 2023 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 23 Dec 2023 18:02:18 -0500 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> Message-ID: <1703372538.ngk50d8uzkgo00ks@hostingemail.digitalspace.net> Ahh thank you so very much Andy! ? On Sat, 23 Dec 2023 16:59:24 -0600, Andy Lester wrote: It?s the current line number. See ?perldoc perlvar? > On Dec 23, 2023, at 4:57?PM, Richard Reina wrote: > > ? > A few years ago I hastily wrote some code that I did not comment very well. In it I found: > > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # match date > > Can anyone tell me what $. means? > > Thanks for any help. > > Richard > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org https://mail.pm.org/mailman/listinfo/chicago-talk ? From dcmertens.perl at gmail.com Sat Dec 23 21:47:04 2023 From: dcmertens.perl at gmail.com (David Mertens) Date: Sun, 24 Dec 2023 00:47:04 -0500 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: <1703372538.ngk50d8uzkgo00ks@hostingemail.digitalspace.net> References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> <1703372538.ngk50d8uzkgo00ks@hostingemail.digitalspace.net> Message-ID: When in doubt, perldoc perlvar Might give you a faster answer than asking the list. Ymmv. :-) On Sat, Dec 23, 2023, 5:02?PM Richard Reina wrote: > Ahh thank you so very much Andy! > > > > > > On Sat, 23 Dec 2023 16:59:24 -0600, Andy Lester wrote: > > It?s the current line number. See ?perldoc perlvar? > > > On Dec 23, 2023, at 4:57?PM, Richard Reina wrote: > > > > ? > > A few years ago I hastily wrote some code that I did not comment very > well. In it I found: > > > > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # > match date > > > > Can anyone tell me what $. means? > > > > Thanks for any help. > > > > Richard > > _______________________________________________ > > Chicago-talk mailing list > > Chicago-talk at pm.org > > https://mail.pm.org/mailman/listinfo/chicago-talk > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.r.ferreira at gmail.com Sun Dec 24 21:02:26 2023 From: a.r.ferreira at gmail.com (Adriano Ferreira) Date: Sun, 24 Dec 2023 21:02:26 -0800 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> <1703372538.ngk50d8uzkgo00ks@hostingemail.digitalspace.net> Message-ID: "perldoc" has the answer, just like mentioned by Andy and David. And "perldoc" has a special trick when you want to look up a special variable. perldoc -v PerlVar In the case of $.: % perldoc -v '$.' HANDLE->input_line_number( EXPR ) $INPUT_LINE_NUMBER $NR $. Current line number for the last filehandle accessed. Each filehandle in Perl counts the number of lines that have been read from it. (Depending on the value of $/, Perl's idea of what constitutes a line may not match yours.) When a line is read from a filehandle (via "readline()" or "<>"), or when "tell()" or "seek()" is called on it, $. becomes an alias to the line counter for that filehandle. You can adjust the counter by assigning to $., but this will not actually move the seek pointer. *Localizing $. will not localize the filehandle's line count*. Instead, it will localize perl's notion of which filehandle $. is currently aliased to. $. is reset when the filehandle is closed, but not when an open filehandle is reopened without an intervening "close()". For more details, see "I/O Operators" in perlop. Because "<>" never does an explicit close, line numbers increase across "ARGV" files (but see examples in "eof" in perlfunc). You can also use "HANDLE->input_line_number(EXPR)" to access the line counter for a given filehandle without having to worry about which handle you last accessed. Mnemonic: many programs use "." to mean the current line number. On Sat, Dec 23, 2023 at 9:47?PM David Mertens wrote: > When in doubt, > > perldoc perlvar > > Might give you a faster answer than asking the list. Ymmv. :-) > > On Sat, Dec 23, 2023, 5:02?PM Richard Reina > wrote: > >> Ahh thank you so very much Andy! >> >> >> >> >> >> On Sat, 23 Dec 2023 16:59:24 -0600, Andy Lester >> wrote: >> >> It?s the current line number. See ?perldoc perlvar? >> >> > On Dec 23, 2023, at 4:57?PM, Richard Reina wrote: >> > >> > ? >> > A few years ago I hastily wrote some code that I did not comment very >> well. In it I found: >> > >> > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # >> match date >> > >> > Can anyone tell me what $. means? >> > >> > Thanks for any help. >> > >> > Richard >> > _______________________________________________ >> > Chicago-talk mailing list >> > Chicago-talk at pm.org >> > https://mail.pm.org/mailman/listinfo/chicago-talk >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> https://mail.pm.org/mailman/listinfo/chicago-talk >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> https://mail.pm.org/mailman/listinfo/chicago-talk >> > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Tue Dec 26 05:31:42 2023 From: richard at rushlogistics.com (Richard Reina) Date: Tue, 26 Dec 2023 08:31:42 -0500 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> <214554ED-2184-4C19-8190-15756691CCCD@petdance.com> <1703372538.ngk50d8uzkgo00ks@hostingemail.digitalspace.net> Message-ID: <1703597502.tq5j3iw000c48cc8@hostingemail.digitalspace.net> Thank you for the tip. ? On Sun, 24 Dec 2023 21:02:26 -0800, Adriano Ferreira wrote: ? ? "perldoc" has the answer, just like mentioned by Andy and David. And "perldoc" has a special trick when you want to look up a special variable. ? ? ? perldoc -v PerlVar ? In the case of $.: ? % perldoc -v '$.' ? ? HANDLE->input_line_number( EXPR ) ? ? $INPUT_LINE_NUMBER ? ? $NR ? ? $. ? ? ?Current line number for the last filehandle accessed. ? ? ? ? ? ? Each filehandle in Perl counts the number of lines that have ? ? ? ? ? ? been read from it. (Depending on the value of $/, Perl's idea of ? ? ? ? ? ? what constitutes a line may not match yours.) When a line is ? ? ? ? ? ? read from a filehandle (via "readline()" or "<>"), or when ? ? ? ? ? ? "tell()" or "seek()" is called on it, $. becomes an alias to the ? ? ? ? ? ? line counter for that filehandle. ? ? ? ? ? ? You can adjust the counter by assigning to $., but this will not ? ? ? ? ? ? actually move the seek pointer. *Localizing $. will not localize ? ? ? ? ? ? the filehandle's line count*. Instead, it will localize perl's ? ? ? ? ? ? notion of which filehandle $. is currently aliased to. ? ? ? ? ? ? $. is reset when the filehandle is closed, but not when an open ? ? ? ? ? ? filehandle is reopened without an intervening "close()". For ? ? ? ? ? ? more details, see "I/O Operators" in perlop. Because "<>" never ? ? ? ? ? ? does an explicit close, line numbers increase across "ARGV" ? ? ? ? ? ? files (but see examples in "eof" in perlfunc). ? ? ? ? ? ? You can also use "HANDLE->input_line_number(EXPR)" to access the ? ? ? ? ? ? line counter for a given filehandle without having to worry ? ? ? ? ? ? about which handle you last accessed. ? ? ? ? ? ? Mnemonic: many programs use "." to mean the current line number. ? ? On Sat, Dec 23, 2023 at 9:47?PM David Mertens wrote: When in doubt, ? perldoc perlvar ? Might give you a faster answer than asking the list. Ymmv. :-) ? On Sat, Dec 23, 2023, 5:02?PM Richard Reina wrote: Ahh thank you so very much Andy! ? On Sat, 23 Dec 2023 16:59:24 -0600, Andy Lester wrote: It?s the current line number. See ?perldoc perlvar? > On Dec 23, 2023, at 4:57?PM, Richard Reina wrote: > > ? > A few years ago I hastily wrote some code that I did not comment very well. In it I found: > > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # match date > > Can anyone tell me what $. means? > > Thanks for any help. > > Richard > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org https://mail.pm.org/mailman/listinfo/chicago-talk ? _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org https://mail.pm.org/mailman/listinfo/chicago-talk _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org https://mail.pm.org/mailman/listinfo/chicago-talk _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org https://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.limardo at forwardphase.com Wed Dec 27 10:22:13 2023 From: joel.limardo at forwardphase.com (J L) Date: Wed, 27 Dec 2023 12:22:13 -0600 Subject: [Chicago-talk] What does dollar sign followed by a period represent? In-Reply-To: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> References: <1703372256.skeqe1mkkksk8cck@hostingemail.digitalspace.net> Message-ID: 1. Have code reviews with pass/fail prior to committing code to a release (yes, scripts should be considered software and as such subject to release cycles) 2. If you cannot, at first glance, understand a regex during this then, 2.1 Save it using a meaningful variable with qr and then use it 2.2 Use the /x modifier and document it ( https://perldoc.perl.org/perlre#%2Fx-and-%2Fxx ) 3. Store metrics on how long your organization spends per quarter/year on problems like this one and adopt structural practices to reduce/eliminate them. I have found the #1 waster is failing to use a well tested CPAN module that does a better job in lieu of barely tested (and, no surprise, largely undocumented) code that 'promised' to save time. People are trying to avoid/refactor Perl scripts because they beleive that six months down the road they will inevitably fall into this type of problem. The fact is however there have been several ways to avoid it in the core language available for decades. On Sat, Dec 23, 2023, 4:57 PM Richard Reina wrote: > > A few years ago I hastily wrote some code that I did not comment very > well. In it I found: > > $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # > match date > > Can anyone tell me what $. means? > > Thanks for any help. > > Richard > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > https://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: