I have a file with a name with three lines:
line oneline secondline three
When I do this:
perl -ne 'print if / one /' file
I get this output:
line one
when i try this:
perl -pe 'next if / one /' file
conclusion:
line onerow secondString tree
I expected the same output as with a single layer. Are my expectations wrong or is something wrong?
Your expectation is wrong. The switch -pplaces the following loop around your code:
-p
LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
If you are reading the documentation fornext , it says:
next
, continue , .
continue
next ( ), .
-
perl -pe '$_ = "" unless /one/' file
, :
-n assume "while (<>) { ... }" loop around program -p assume loop like -n but print line also, like sed
.
perl -ne 'print if /one/' file
"" .
perl -ne 'next unless /one/' file
, -p.
perl -pe 'next unless /one/' file
, , , - -p .
$ perl -ne 'next unless /one/ && print' file line one
Source: https://habr.com/ru/post/1735768/More articles:Why are my groovy listings not working or even not compiling? - enumsEcho styles in the mashup of google maps and custom Wordpress fields - javascriptLooking for numbers in a string? - javaAn entry in the classpath eclipse.fproj.jdt.libprov.osgi / jpt.jpa is marked for publication / export, but is not exported to the project class path - eclipseUITableView visibleCells (in section?) - iphoneQuestion about operator overloading + - c ++Silverlight / WPF. Can I change the tag frequency to CategoryAxis? - chartsHow is the behavior of if- and if if different? expression affects range operator in scalar context? - operator-precedenceDisplay view from another view - ruby | fooobar.comInvoking a delegate question - c #All Articles