# Blocchi e cicli

**URL:** <https://www.ruby-forum.com/t/blocchi-e-cicli/149148>\
**Category:** IT\
**Created:** [September 21, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/blocchi-e-cicli/149148 "2008-09-21T19:53:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnaudo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@arnaudo](https://www.ruby-forum.com/u/arnaudo)\
**Post date:** [September 21, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/blocchi-e-cicli/149148/1 "2008-09-21T19:53:24Z")

</div>

Ciao a tutti,  
lanciando il file ho un errore:

#!/usr/bin/env ruby

require ‘pathname’

p = Pathname.new(‘c:\Download\’)  
elenco\_file = p.entries # passa all’array i valori della directory  
elenco\_file\_txt = elenco\_file.select {|entry| entry.to\_s =~ /pdf/ }.sort  
puts elenco\_file\_txt[0] # invia a video il risultato

contatore\_file = 0  
while elenco\_file\_txt[contatore\_file] = nil {  
puts elenco\_file\_txt[contatore\_file]  
contatore\_file=contatore\_file+1  
}  
print “non esistono file txt”  
end

SyntaxError: compile error  
txt\_to\_ics\_2.rb:20: syntax error, unexpected ‘{’, expecting kDO\_COND or  
‘:’ or ’  
\n’ or ‘;’  
txt\_to\_ics\_2.rb:23: syntax error, unexpected ‘}’, expecting $end  
from txt\_to\_ics\_2.rb:23

Mi sapreste suggerire l’errore?

Grazie  
Massimo

---

<div class="post-metadata">

**Author:** ![arnaudo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@arnaudo](https://www.ruby-forum.com/u/arnaudo)\
**Post date:** [September 21, 2008, 9:14pm UTC](https://www.ruby-forum.com/t/blocchi-e-cicli/149148/2 "2008-09-21T21:14:33Z")

</div>

2008/9/21 Massimo A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Ciao a tutti,  
> lanciando il file ho un errore:

Se ho capito cosa vuoi fare, prova con questo:

require ‘pathname’

elenco\_file = Pathname.new(‘c:\Download\’).entries  
elenco\_file\_txt = elenco\_file.select {|entry| entry.to\_s =~ // }.sort  
puts “Non esistono file txt” if elenco\_file\_txt.empty?  
elenco\_file\_txt.each {|file| puts file }

## Ciao, Antonio

[http://antoniocangiano.com](http://antoniocangiano.com) - Zen and the Art of Programming  
[http://belifesavvy.com](http://belifesavvy.com) - Be life savvy: Life’s missing manual  
[http://stacktrace.it](http://stacktrace.it) - Aperiodico di resistenza informatica  
Currently writing “Ruby on Rails for Microsoft Developers” for Wrox.

---

<div class="post-metadata">

**Author:** ![arnaudo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@arnaudo](https://www.ruby-forum.com/u/arnaudo)\
**Post date:** [October 11, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/blocchi-e-cicli/149148/3 "2008-10-11T16:13:15Z")

</div>

Qui cos’Ã¨ che Ã¨ successo ??

> while elenco\_file\_txt[contatore\_file] = nil {  
> puts elenco\_file\_txt[contatore\_file]  
> contatore\_file=contatore\_file+1  
> }  
> print “non esistono file txt”  
> end

Cos’Ã¨ quel blocco aperto? L’errore dice

> unexpected ‘{’, expecting kDO\_COND or  
> ‘:’ or ’  
> \n’ or ‘;’

CioÃ¨, il parser non si aspetta il carattere “{”; si sarebbe aspettato il  
“do”, i due punti “:” o il punto e virgola “;”, oppure un new line.

E poi la condizione del while Ã¨ completamente errata, anche perchÃ¨ non Ã¨  
una condizione ma un assegnamento (e ritorna nil dunque).
