perl

perl --> printing characters in between the multiple metacharacters present in a single line

血红的双手。 提交于 2021-01-29 10:14:51
问题 I am trying a script to find out the characters between the metacharacter "|". I tried to get the position of the first and the succeeding "|" metacharacter and tried to print the string between those two positions. Below is the code I tried: File : | A| B| Count| D| E| Expected output : A B Count D E if($line =~ /\|/) { while ($line =~ m/\|/g) { my $start_pos = $-[0]; my $end_pos = $+[0]; my $hit_pos = "$start_pos - $end_pos"; my $char = substr($line, $start_pos, $end_pos); if($char =~/\w/){

perl remove string block from file and save to file

我与影子孤独终老i 提交于 2021-01-29 09:00:52
问题 I have a file that looks like this: string 1 { abc { session 1 } fairPrice { ID LU0432618274456 Source 4 service xyz } } string 2 { abc { session 23 } fairPrice { ID LU036524565456171 Source 4 service tzu } } My program should read in the file with a search-parameter given (for example "string 1") and search the complete block until "}" and remove that part from the file. Can someone assist on that...I have some code so far but how can I do the removal and saving to the same file again? my

DBD::DB2 installation failing because of test using cpan on Strawberry Perl

ⅰ亾dé卋堺 提交于 2021-01-29 07:57:15
问题 I am very new to perl and I am trying to install DBD::DB2 module for perl on a windows PC using cpan but I keep getting this error: CPAN: CPAN::SQLite loaded ok (v0.212) Database was generated on Thu, 06 Dec 2018 20:55:19 GMT Running install for module 'DBD::DB2' CPAN: Digest::SHA loaded ok (v6.02) CPAN: Compress::Zlib loaded ok (v2.081) Checksum for D:\STRAWB~1\cpan\sources\authors\id\I\IB\IBMTORDB2\DBD-DB2-1.85.tar.gz ok CPAN: Archive::Tar loaded ok (v2.32) CPAN: YAML::XS loaded ok (v0.75)

How can I escape quotes on a PHP system call?

蓝咒 提交于 2021-01-29 05:59:09
问题 I'm passing to perl from php using escapeshellarg system("perl -e '" . escapeshellarg($inp) . "' >> /tmp/out"); And get unterminated quoted string from perl. Input is: 'Single quoted terminated string\n'; 回答1: Please note that escapeshellarg adds the outer single quotes itself. So you should leave them out: system("perl -e " . escapeshellarg($inp) . " >> /tmp/out"); # ^ ^ no extra ' quotes here 来源: https://stackoverflow.com/questions/11331125/how-can-i-escape-quotes-on-a-php-system-call

Locking a file for both read and write

偶尔善良 提交于 2021-01-29 01:59:13
问题 I am writing an application where two processes needs to update the same file file.txt . There is a chance that this will happen at the same time, so I should implement some locking framework. Each process needs to first read all of file.txt , process it, and then write out a modified verison of file.txt . So the lock should be obtained before the first file read, and released after the write. I checked out flock in Fcntl but it seems it can only lock on a filehandle, so the lock is lost

Is it possible to rename PascalCase1.wav to kebab-case-1.wav with a single perl regex?

时间秒杀一切 提交于 2021-01-29 00:45:00
问题 Here is a sample of my data: SomePascalCase.wav ThingsThat1.wav Are.wav Here.wav Here is the result I'm looking for: some-pascal-case.wav things-that-1.wav are.wav here.wav Here is what I used: for f in *.wav; do mv "$f" $( echo "$f" | perl -pe 's/([A-Z])([a-z]+)(?=[0-9A-Z])/\L\1\2-/g' | perl -pe 's/([A-Z])([a-z]+)(?=.wav)/\L\1\2/g' ) done Is it possible to consolidate the two regular expressions I used into a single one? 回答1: You wouldn't really use a regex substitution here. You would use

Is it possible to rename PascalCase1.wav to kebab-case-1.wav with a single perl regex?

我的梦境 提交于 2021-01-29 00:40:55
问题 Here is a sample of my data: SomePascalCase.wav ThingsThat1.wav Are.wav Here.wav Here is the result I'm looking for: some-pascal-case.wav things-that-1.wav are.wav here.wav Here is what I used: for f in *.wav; do mv "$f" $( echo "$f" | perl -pe 's/([A-Z])([a-z]+)(?=[0-9A-Z])/\L\1\2-/g' | perl -pe 's/([A-Z])([a-z]+)(?=.wav)/\L\1\2/g' ) done Is it possible to consolidate the two regular expressions I used into a single one? 回答1: You wouldn't really use a regex substitution here. You would use

When using multiple inheritance in Perl is there a way to indicate which SUPER function to use?

元气小坏坏 提交于 2021-01-28 19:32:05
问题 As per the title, I'm working on an awkward bit of code that makes use of multiple inheritance and requires that the two SUPER functions both be called. Is there a way of indicating to Perl which of the two parent classes I want to run the function from? Using $self->SUPER::foo($bar); only runs the first matching function in @ISA as per the documentation. The following gives an idea of how the classes are inherited: [Base Class] | ---------------------------- | | [A] [B] | | -----------------

How do I pass Shell parameters to Perl script?

时光怂恿深爱的人放手 提交于 2021-01-28 19:07:21
问题 I am trying to find dates with in a certain format, I have done it before with perl( strftime ), but that time I mentioned a static time, this time i need a variable $CURRENT_DAY here. Below is the issue, when equate the CURRENT_DAY by using DAYHOUR=86400 and an integer, the variable is giving the right time, but once I put $CURRENT_DAY variable in the statement, the date would not decrease. $ DAYHOUR=86400 $ DAY=1 $ CURRENT_DAY=`echo $(($DAYHOUR*$DAY))` $ DD=`perl -e 'use POSIX; print

Use Perl to check if a string has only English characters

感情迁移 提交于 2021-01-28 18:18:26
问题 I have a file with submissions like this %TRYYVJT128F93506D3<SEP>SOYKCDV12AB0185D99<SEP>Rainie Yang<SEP>Ai Wo Qing shut up (OT: Shotgun(Aka Shot Gun)) %TRYYVHU128F933CCB3<SEP>SOCCHZY12AB0185CE6<SEP>Tepr<SEP>Achète-moi I am stripping everything but the song name by using this regex. $line =~ s/.*>|([([\/\_\-:"``+=*].*)|(feat.*)|[?¿!¡\.;&\$@%#\\|]//g; I want to make sure that the only strings printed are ones that contain only English characters, so in this case it would the first song title Ai