🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.perl
Article #52251

Re: [RegEx] Parametr opcjonalny w wyrażeniu regularnym

#52251
From: Maciej Misiak
Date: Thu, 09 Jun 2011 22:06
32 lines
1928 bytes
W dniu 2011-06-09 12:09, Scottie pisze:
> Cześć!
> Mam problem<...>

Problem jest ten, że nie zawsze w linii występuje słowo 'datafile', 
które w Twoim regexpie jest konieczne.
Po poprawieniu regexpa na
/channel.*starting\s(?!piece)(.*)\s(.*)\s(datafile)?.*/
problemem staje się warunek (?!piece), który nie jest spełniony w co 
drugiej linii. I znowu cały regexp się nie dopasowuje, a więc wynikiem 
jest 'uninitialized variable'.

Generalnie ja bym poszedł na łatwiznę:

#!/usr/bin/perl
use warnings;
use strict;

while (<DATA>) {
     if(/starting\s(?!piece)/)
     {
			my ($backup_compressed, $type_of_backup ) = ('No', 'Not Full');
			if(/compressed/i)
				{ $backup_compressed = 'Yes' }
			if(/full/i)
				{ $type_of_backup = 'Full' }
	    print "|$backup_compressed|$type_of_backup|\n";
     }
}

-- 
grizzley
Technical Details
Message-ID: <isrg5v$eo6$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.onet.pl!.POSTED!not-for-mail
References: <64fb46cb-5161-4fe6-b574-aa65b14dad3e@c26g2000vbq.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.onet.pl!.POSTED!not-for-mail
From: Maciej Misiak <grizzley@poczta.onet.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: [RegEx] Parametr opcjonalny w wyrażeniu
 regularnym
Date: Fri, 10 Jun 2011 00:06:54 +0200
Organization: http://onet.pl
Lines: 32
Message-ID: <isrg5v$eo6$1@news.onet.pl>
References: <64fb46cb-5161-4fe6-b574-aa65b14dad3e@c26g2000vbq.googlegroups.com>
NNTP-Posting-Host: ip-62-69-199-251.globalconnect.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1307657215 15110 62.69.199.251 (9 Jun 2011 22:06:55 GMT)
X-Complaints-To: niusy@onet.pl
NNTP-Posting-Date: Thu, 9 Jun 2011 22:06:55 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 ThunderBrowse/3.3.5
In-Reply-To: <64fb46cb-5161-4fe6-b574-aa65b14dad3e@c26g2000vbq.googlegroups.com>
X-Antivirus: avast! (VPS 110609-0, 2011-06-09), Outbound message
X-Antivirus-Status: Clean
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit